From 1caaf52b21aeae66d2bdc6286f5aa26b7a206512 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 12 Jun 2017 18:01:10 +0100 Subject: [PATCH 1/5] support arbitrary user IDs in BDD tests --- .travis.yml | 13 ++++++++++++- features/exec_non_interactive.feature | 12 ++++++------ features/interactive_stdin.feature | 4 ++-- features/non_interactive.feature | 14 ++++++++------ features/steps/step_definitions.py | 10 +++++++++- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89a7792..007250e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,17 @@ matrix: env: REQUIREMENTS=requirements3-dev.txt VENV=python3.4 services: - docker + - python: "3.5" + env: REQUIREMENTS=requirements3-dev.txt VENV=python3.5 + services: + - docker + - python: "3.6" + env: REQUIREMENTS=requirements3-dev.txt VENV=python3.5 + services: + - docker install: pip install -r $REQUIREMENTS -script: py.test -q tests && behave -c --no-capture -q +script: + - py.test -q tests + - behave -c --no-capture -q +cache: pip diff --git a/features/exec_non_interactive.feature b/features/exec_non_interactive.feature index 766321d..bdf05da 100644 --- a/features/exec_non_interactive.feature +++ b/features/exec_non_interactive.feature @@ -25,9 +25,9 @@ Feature: Executing command in a running docker container non-interactively And I run "cat" in a docker container with stdin open And I start the container When I exec "/bin/tail -f -n1 /etc/passwd" in a running docker container - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -36,9 +36,9 @@ Feature: Executing command in a running docker container non-interactively And I run "cat" in a docker container with stdin open And I start the container When I exec "sh -c 'tail -f -n1 /etc/passwd 1>&2'" in a running docker container - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -48,8 +48,8 @@ Feature: Executing command in a running docker container non-interactively And I start the container When I exec "/bin/tail -f -n1 /etc/passwd" in a running docker container And I press ENTER - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ And The container will still be running diff --git a/features/interactive_stdin.feature b/features/interactive_stdin.feature index 3e0add5..636d82a 100644 --- a/features/interactive_stdin.feature +++ b/features/interactive_stdin.feature @@ -24,9 +24,9 @@ Feature: Attaching to a docker container with stdin open Given I am using a TTY And I run "tail -n1 -f /etc/passwd" in a docker container with stdin open When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ diff --git a/features/non_interactive.feature b/features/non_interactive.feature index 9a4f5c5..0ce7c2e 100644 --- a/features/non_interactive.feature +++ b/features/non_interactive.feature @@ -24,9 +24,9 @@ Feature: Attaching to a docker container non-interactively Given I am using a TTY And I run "/bin/tail -f -n1 /etc/passwd" in a docker container When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -34,19 +34,21 @@ Feature: Attaching to a docker container non-interactively Given I am using a TTY And I run "sh -c 'tail -f -n1 /etc/passwd 1>&2'" in a docker container When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ + + Scenario: Ignoring input Given I am using a TTY And I run "/bin/tail -n1 -f /etc/passwd" in a docker container When I start dockerpty And I press ENTER - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ And The container will still be running diff --git a/features/steps/step_definitions.py b/features/steps/step_definitions.py index 2ac575f..74121cc 100644 --- a/features/steps/step_definitions.py +++ b/features/steps/step_definitions.py @@ -15,7 +15,7 @@ # limitations under the License. from behave import then, given, when -from expects import expect, equal, be_true, be_false +from expects import expect, equal, be_true, be_false, match import tests.util as util import dockerpty @@ -197,6 +197,14 @@ def step_impl(ctx): expect(actual[-len(wanted):]).to(equal(wanted)) +@then('I will see output matching') +def step_impl(ctx): + # you should check `actual` when tests fail + actual = util.read_printable(ctx.pty) + wanted = ctx.text + expect(actual).to(match(wanted)) + + @then('The PTY will be closed cleanly') def step_impl(ctx): if not hasattr(ctx, "exit_code"): From 0aa8da6e270864deab5e5680c434f12773e1a849 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 22 Jun 2017 14:44:58 +0100 Subject: [PATCH 2/5] remove unused VENV env --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 007250e..e857c20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,23 +23,23 @@ language: python matrix: include: - python: "2.7" - env: REQUIREMENTS=requirements-dev.txt VENV=python2.7 + env: REQUIREMENTS=requirements-dev.txt services: - docker - python: "pypy" - env: REQUIREMENTS=requirements-dev.txt VENV=pypy + env: REQUIREMENTS=requirements-dev.txt services: - docker - python: "3.4" - env: REQUIREMENTS=requirements3-dev.txt VENV=python3.4 + env: REQUIREMENTS=requirements3-dev.txt services: - docker - python: "3.5" - env: REQUIREMENTS=requirements3-dev.txt VENV=python3.5 + env: REQUIREMENTS=requirements3-dev.txt services: - docker - python: "3.6" - env: REQUIREMENTS=requirements3-dev.txt VENV=python3.5 + env: REQUIREMENTS=requirements3-dev.txt services: - docker From e7e7969dd35e2777dde945ecd8da63e218da392b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 22 Jun 2017 14:53:10 +0100 Subject: [PATCH 3/5] use the deprecated images for pypy --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e857c20..7ace838 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ matrix: - docker - python: "pypy" env: REQUIREMENTS=requirements-dev.txt + group: deprecated-2017Q2 services: - docker - python: "3.4" From e017dd74c39aed674f7c00b204407df33e714625 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 22 Jun 2017 15:06:32 +0100 Subject: [PATCH 4/5] add more pythons to tox --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 444b01d..06678d3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,11 @@ [tox] -envlist = py27, pypy, py34 +envlist = py27, pypy, pypy3, py3{4,5,6} [testenv] deps = py27: -rrequirements-dev.txt pypy: -rrequirements-dev.txt - py34: -rrequirements3-dev.txt + py3{4,5,6}: -rrequirements3-dev.txt commands = py.test -v tests/ behave From a6a3d2ed0a19dd288d92f24ea9737762beef61d0 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 22 Jun 2017 15:25:27 +0100 Subject: [PATCH 5/5] skip failing test --- features/environment.py | 7 +++++++ features/interactive_stdin.feature | 1 + 2 files changed, 8 insertions(+) diff --git a/features/environment.py b/features/environment.py index 964dcbf..e188498 100644 --- a/features/environment.py +++ b/features/environment.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + from docker.errors import NotFound from utils import get_client @@ -44,3 +46,8 @@ def after_scenario(ctx, scenario): ctx.client.remove_container(ctx.container, force=True) except: pass + + +def before_scenario(context, scenario): + if "skip3" in scenario.effective_tags and sys.version_info >= (3,0): + scenario.skip("Marked with @skip3 and running on Python 3") diff --git a/features/interactive_stdin.feature b/features/interactive_stdin.feature index 636d82a..1c775c5 100644 --- a/features/interactive_stdin.feature +++ b/features/interactive_stdin.feature @@ -76,6 +76,7 @@ Feature: Attaching to a docker container with stdin open """ + @skip3 Scenario: Closing input Given I am using a TTY And I run "/bin/cat" in a docker container with stdin open