-
Notifications
You must be signed in to change notification settings - Fork 2.3k
adds client api integration tests for runc using bash w/bats #659
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
Merged
crosbymichael
merged 1 commit into
opencontainers:master
from
mikebrow:integration-test-bats
Apr 22, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| # runc Integration Tests | ||
|
|
||
| Integration tests provide end-to-end testing of runc. | ||
|
|
||
| Note that integration tests do **not** replace unit tests. | ||
|
|
||
| As a rule of thumb, code should be tested thoroughly with unit tests. | ||
| Integration tests on the other hand are meant to test a specific feature end | ||
| to end. | ||
|
|
||
| Integration tests are written in *bash* using the | ||
| [bats](https://github.com/sstephenson/bats) framework. | ||
|
|
||
| ## Running integration tests | ||
|
|
||
| The easiest way to run integration tests is with Docker: | ||
| ``` | ||
| $ make integration | ||
| ``` | ||
| Alternatively, you can run integration tests directly on your host through make: | ||
| ``` | ||
| $ sudo make localintegration | ||
| ``` | ||
| Or you can just run them directly using bats | ||
| ``` | ||
| $ sudo bats tests/integration | ||
| ``` | ||
| To run a single test bucket: | ||
| ``` | ||
| $ make integration TESTFLAGS="/checkpoint.bats" | ||
| ``` | ||
|
|
||
|
|
||
| To run them on your host, you will need to setup a development environment plus | ||
| [bats](https://github.com/sstephenson/bats#installing-bats-from-source) | ||
| For example: | ||
| ``` | ||
| $ cd ~/go/src/github.com | ||
| $ git clone https://github.com/sstephenson/bats.git | ||
| $ cd bats | ||
| $ ./install.sh /usr/local | ||
| ``` | ||
|
|
||
| > **Note**: There are known issues running the integration tests using | ||
| > **devicemapper** as a storage driver, make sure that your docker daemon | ||
| > is using **aufs** if you want to successfully run the integration tests. | ||
|
|
||
| ## Writing integration tests | ||
|
|
||
| [helper functions] | ||
| (https://github.com/opencontainers/runc/blob/master/test/integration/helpers.bash) | ||
| are provided in order to facilitate writing tests. | ||
|
|
||
| ```sh | ||
| #!/usr/bin/env bats | ||
|
|
||
| # This will load the helpers. | ||
| load helpers | ||
|
|
||
| # setup is called at the beginning of every test. | ||
| function setup() { | ||
| # see functions teardown_hello and setup_hello in helpers.bash, used to | ||
| # create a pristine environment for running your tests | ||
| teardown_hello | ||
| setup_hello | ||
| } | ||
|
|
||
| # teardown is called at the end of every test. | ||
| function teardown() { | ||
| teardown_hello | ||
| } | ||
|
|
||
| @test "this is a simple test" { | ||
| run "$RUNC" start containerid | ||
| # "run" automatically populates $status, $output and $lines. | ||
| # Please refer to bats documentation to find out more. | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # check expected output | ||
| [[ "${output}" == *"Hello"* ]] | ||
| } | ||
|
|
||
| ``` |
This file contains hidden or 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,61 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load helpers | ||
|
|
||
| function setup() { | ||
| teardown_busybox | ||
| setup_busybox | ||
| } | ||
|
|
||
| function teardown() { | ||
| teardown_busybox | ||
| } | ||
|
|
||
| @test "checkpoint and restore" { | ||
| if [ ! -e "$CRIU" ] ; then | ||
| skip | ||
| fi | ||
|
|
||
| # criu does not work with external terminals so.. | ||
| # setting terminal and root:readonly: to false | ||
| sed -i 's;"terminal": true;"terminal": false;' config.json | ||
| sed -i 's;"readonly": true;"readonly": false;' config.json | ||
| sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json | ||
|
|
||
| ( | ||
| # start busybox (not detached) | ||
| run "$RUNC" start test_busybox | ||
| [ "$status" -eq 0 ] | ||
| ) & | ||
|
|
||
| # check state | ||
| wait_for_container 15 1 test_busybox | ||
|
|
||
| run "$RUNC" state test_busybox | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *"running"* ]] | ||
|
|
||
| # checkpoint the running container | ||
| run "$RUNC" --criu "$CRIU" checkpoint test_busybox | ||
| # if you are having problems getting criu to work uncomment the following dump: | ||
| #cat /run/opencontainer/containers/test_busybox/criu.work/dump.log | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # after checkpoint busybox is no longer running | ||
| run "$RUNC" state test_busybox | ||
| [ "$status" -ne 0 ] | ||
|
|
||
| # restore from checkpoint | ||
| ( | ||
| run "$RUNC" --criu "$CRIU" restore test_busybox | ||
| [ "$status" -eq 0 ] | ||
| ) & | ||
|
|
||
| # check state | ||
| wait_for_container 15 1 test_busybox | ||
|
|
||
| # busybox should be back up and running | ||
| run "$RUNC" state test_busybox | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *"running"* ]] | ||
| } |
This file contains hidden or 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,70 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load helpers | ||
|
|
||
| function setup() { | ||
| teardown_hello | ||
| setup_hello | ||
| } | ||
|
|
||
| function teardown() { | ||
| teardown_hello | ||
| } | ||
|
|
||
| @test "global --debug" { | ||
| # start hello-world | ||
| run "$RUNC" --debug start test_hello | ||
| echo "${output}" | ||
| [ "$status" -eq 0 ] | ||
| } | ||
|
|
||
| @test "global --debug to --log" { | ||
| # start hello-world | ||
| run "$RUNC" --log log.out --debug start test_hello | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # check output does not include debug info | ||
| [[ "${output}" != *"level=debug"* ]] | ||
|
|
||
| # check log.out was generated | ||
| [ -e log.out ] | ||
|
|
||
| # check expected debug output was sent to log.out | ||
| run cat log.out | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *"level=debug"* ]] | ||
| } | ||
|
|
||
| @test "global --debug to --log --log-format 'text'" { | ||
| # start hello-world | ||
| run "$RUNC" --log log.out --log-format "text" --debug start test_hello | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # check output does not include debug info | ||
| [[ "${output}" != *"level=debug"* ]] | ||
|
|
||
| # check log.out was generated | ||
| [ -e log.out ] | ||
|
|
||
| # check expected debug output was sent to log.out | ||
| run cat log.out | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *"level=debug"* ]] | ||
| } | ||
|
|
||
| @test "global --debug to --log --log-format 'json'" { | ||
| # start hello-world | ||
| run "$RUNC" --log log.out --log-format "json" --debug start test_hello | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # check output does not include debug info | ||
| [[ "${output}" != *"level=debug"* ]] | ||
|
|
||
| # check log.out was generated | ||
| [ -e log.out ] | ||
|
|
||
| # check expected debug output was sent to log.out | ||
| run cat log.out | ||
| [ "$status" -eq 0 ] | ||
| [[ "${output}" == *'"level":"debug"'* ]] | ||
| } |
This file contains hidden or 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,33 @@ | ||
| #!/usr/bin/env bats | ||
|
|
||
| load helpers | ||
|
|
||
| function setup() { | ||
| teardown_busybox | ||
| setup_busybox | ||
| } | ||
|
|
||
| function teardown() { | ||
| teardown_busybox | ||
| } | ||
|
|
||
| @test "runc delete" { | ||
| # start busybox detached | ||
| run "$RUNC" start -d --console /dev/pts/ptmx test_busybox | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| # check state | ||
| wait_for_container 15 1 test_busybox | ||
|
|
||
| testcontainer test_busybox running | ||
|
|
||
| run "$RUNC" kill test_busybox KILL | ||
| # wait for busybox to be in the destroyed state | ||
| retry 10 1 eval "'$RUNC' state test_busybox | grep -q 'destroyed'" | ||
|
|
||
| # delete test_busybox | ||
| run "$RUNC" delete test_busybox | ||
|
|
||
| run "$RUNC" state test_busybox | ||
| [ "$status" -ne 0 ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should specify an exact commit or version in the repo to checkout. This means that we don't have to worry about inconsistencies in the test framework. Please also strip the trailing whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the trailing whitespace from this file... Per Michael's comment leaving the which/how of picking or caching a particular version of bats for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he meant "we should add it to the Jenkins jobs in another PR". I don't like pulling in the latest version of bats from HEAD when doing testing -- that doesn't strike me as being a particularly good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk... np... updated to reset head back to a known commit (which is the latest atm).
Cheers.