diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..25853168b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/sharness"] + path = test/sharness + url = git://github.com/mlafeldt/sharness.git diff --git a/.travis.yml b/.travis.yml index 6636a9981..0a91e977b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,4 @@ script: - git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE} - make - make test + - PATH="${PATH}:${PWD}" make -C test diff --git a/test/Makefile b/test/Makefile new file mode 120000 index 000000000..56e78a978 --- /dev/null +++ b/test/Makefile @@ -0,0 +1 @@ +sharness/test/Makefile \ No newline at end of file diff --git a/test/README.md b/test/README.md new file mode 100644 index 000000000..c1df1a88d --- /dev/null +++ b/test/README.md @@ -0,0 +1,42 @@ +# oci-runtime-tool integration tests + +This project uses the [Sharness][] test harness, installed as a [Git +submodule][submodule]. To setup the test installation after a clone, +run: + + $ git submodule update --init + +which will checkout the appropriate Sharness commit in the `sharness` +directory (after which the `Makefile`, `sharness.sh`, etc. symlinks +will resolve successfully). + +Run the tests with: + + $ make + +And read the `Makefile` source to find other useful targets +(e.g. [`prove`][prove]). + +## Naming + +0 - Global `oci-runtime-tool` options. + +1 - `oci-runtime-tool generate`. + +## Dependencies + +* [GNU Core Utilities][coreutils] for [`cat`][cat.1], + [`echo`][echo.1], [`head`][head.1], and [`sed][sed.1]. +* [jq] for [`jq`][jq.1]. + +[coreutils]: http://www.gnu.org/software/coreutils/coreutils.html +[jq]: https://stedolan.github.io/jq/ +[prove]: http://perldoc.perl.org/prove.html +[Sharness]: http://mlafeldt.github.io/sharness/ +[submodule]: http://git-scm.com/docs/git-submodule + +[cat.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cat.html +[echo.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html +[head.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html +[jq.1]: https://stedolan.github.io/jq/manual/ +[sed.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html diff --git a/test/aggregate-results.sh b/test/aggregate-results.sh new file mode 120000 index 000000000..6fbcf3704 --- /dev/null +++ b/test/aggregate-results.sh @@ -0,0 +1 @@ +sharness/aggregate-results.sh \ No newline at end of file diff --git a/test/sharness b/test/sharness new file mode 160000 index 000000000..64595a27f --- /dev/null +++ b/test/sharness @@ -0,0 +1 @@ +Subproject commit 64595a27fdc0271e826b19461d58bab6e319a968 diff --git a/test/sharness.d/miscellaneous.sh b/test/sharness.d/miscellaneous.sh new file mode 100644 index 000000000..3ce47ac95 --- /dev/null +++ b/test/sharness.d/miscellaneous.sh @@ -0,0 +1,3 @@ +command -v jq >/dev/null 2>/dev/null && test_set_prereq JQ + +true diff --git a/test/sharness.d/posix-utilities.sh b/test/sharness.d/posix-utilities.sh new file mode 100644 index 000000000..e57e1802e --- /dev/null +++ b/test/sharness.d/posix-utilities.sh @@ -0,0 +1,6 @@ +command -v cat >/dev/null 2>/dev/null && test_set_prereq CAT +command -v echo >/dev/null 2>/dev/null && test_set_prereq ECHO +command -v head >/dev/null 2>/dev/null && test_set_prereq HEAD +command -v sed >/dev/null 2>/dev/null && test_set_prereq SED + +true diff --git a/test/sharness.sh b/test/sharness.sh new file mode 120000 index 000000000..41f139032 --- /dev/null +++ b/test/sharness.sh @@ -0,0 +1 @@ +sharness/sharness.sh \ No newline at end of file diff --git a/test/t0001-oci-runtime-tool.t b/test/t0001-oci-runtime-tool.t new file mode 100755 index 000000000..9a7c959db --- /dev/null +++ b/test/t0001-oci-runtime-tool.t @@ -0,0 +1,22 @@ +#!/bin/sh + +test_description='Test ocitools global options' + +. ./sharness.sh + +test_expect_success CAT,HEAD 'Test oci-runtime-tool --help' " + oci-runtime-tool --help | head -n2 >actual && + cat <<-EOF >expected && + NAME: + oci-runtime-tool - OCI (Open Container Initiative) runtime tools + EOF + test_cmp expected actual +" + +test_expect_success ECHO,SED 'Test oci-runtime-tool --version' " + oci-runtime-tool --version | sed 's/commit: [0-9a-f]*$/commit: HASH/' >actual && + echo 'oci-runtime-tool version 0.0.1, commit: HASH' >expected && + test_cmp expected actual +" + +test_done diff --git a/test/t1000-generate-output.t b/test/t1000-generate-output.t new file mode 100755 index 000000000..34a30d92f --- /dev/null +++ b/test/t1000-generate-output.t @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='Test generate output' + +. ./sharness.sh + +test_expect_success CAT,HEAD 'Test oci-runtime-tool generate writing to stdout' " + oci-runtime-tool generate | head -n2 >actual && + cat <expected && +{ + \"ociVersion\": \"1.0.0\", +EOF + test_cmp expected actual +" + +test_expect_success CAT,HEAD 'Test oci-runtime-tool generate --output' " + oci-runtime-tool generate --output config.json && + head -n2 config.json >actual && + cat <expected && +{ + \"ociVersion\": \"1.0.0\", +EOF + test_cmp expected actual +" + +test_done diff --git a/test/t1001-generate-template.t b/test/t1001-generate-template.t new file mode 100755 index 000000000..9753418bf --- /dev/null +++ b/test/t1001-generate-template.t @@ -0,0 +1,51 @@ +#!/bin/sh + +test_description='Test generate template' + +. ./sharness.sh + +test_expect_success CAT,ECHO,HEAD,JQ 'Test oci-runtime-tool generate --template with an empty template' " + echo '{}' >template && + oci-runtime-tool generate --template template | jq . >actual && + cat <<-EOF >expected && + { + \"ociVersion\": \"1.0.0\", + \"process\": { + \"user\": { + \"uid\": 0, + \"gid\": 0 + }, + \"args\": null, + \"cwd\": \"/\" + }, + \"root\": { + \"path\": \"rootfs\" + } + } + EOF + test_cmp expected actual +" + +test_expect_success CAT,HEAD,JQ 'Test oci-runtime-tool generate --template with a different version' " + echo '{\"ociVersion\": \"1.0.0-rc9\"}' >template && + oci-runtime-tool generate --template template | jq . >actual && + cat <<-EOF >expected && + { + \"ociVersion\": \"1.0.0-rc9\", + \"process\": { + \"user\": { + \"uid\": 0, + \"gid\": 0 + }, + \"args\": null, + \"cwd\": \"/\" + }, + \"root\": { + \"path\": \"rootfs\" + } + } + EOF + test_cmp expected actual +" + +test_done