-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e589c6
commit a7e72f4
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pytest | ||
|
||
def test_bash_true_results_in_0(host): | ||
output = host.run('bash -c "true"') | ||
assert output.rc == 0 | ||
|
||
def test_bash_true_results_in_0(host): | ||
output = host.run('bash -c "false"') | ||
assert output.rc > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
|
||
def test_user_app(host): | ||
userName = 'runner' | ||
groupName = 'runner' | ||
homeDir = '/home/runner' | ||
|
||
usr = host.user(userName) | ||
assert userName in usr.name | ||
assert groupName in usr.group | ||
assert homeDir in usr.home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# | ||
# A simple script to start a Docker container | ||
# and run Testinfra in it | ||
# Original script: https://gist.github.com/renatomefi/bbf44d4e8a2614b1390416c6189fbb8e | ||
# Author: @renatomefi https://github.com/renatomefi | ||
# | ||
|
||
set -eEuo pipefail | ||
|
||
# The first parameter is a Docker tag or image id | ||
declare -r DOCKER_TAG="$1" | ||
|
||
printf "Starting a container for '%s'\\n" "$DOCKER_TAG" | ||
|
||
DOCKER_CONTAINER=$(docker run --rm -v "$(pwd)/test:/tests" -t -d "$DOCKER_TAG") | ||
readonly DOCKER_CONTAINER | ||
|
||
# Let's register a trap function, if our tests fail, finish or the script gets | ||
# interrupted, we'll still be able to remove the running container | ||
function tearDown { | ||
docker rm -f "$DOCKER_CONTAINER" &>/dev/null & | ||
} | ||
trap tearDown EXIT TERM ERR | ||
|
||
# Finally, run the tests! | ||
echo "Running test suite" | ||
docker run --rm -t \ | ||
-v "$(pwd)/test:/tests" \ | ||
-v "$(pwd)/tmp/test-results:/results" \ | ||
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
renatomefi/docker-testinfra:5 \ | ||
--disable-pytest-warnings \ | ||
--verbose --hosts="docker://$DOCKER_CONTAINER" |