Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix travis tests by supporting arbitrary user IDs in BDD #76

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,29 @@ 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
group: deprecated-2017Q2
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
services:
- docker
- python: "3.6"
env: REQUIREMENTS=requirements3-dev.txt
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
7 changes: 7 additions & 0 deletions features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
12 changes: 6 additions & 6 deletions features/exec_non_interactive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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$
"""


Expand All @@ -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$
"""


Expand All @@ -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
5 changes: 3 additions & 2 deletions features/interactive_stdin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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$
"""


Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions features/non_interactive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ 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$
"""


Scenario: Capturing errors
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
10 changes: 9 additions & 1 deletion features/steps/step_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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