From 509117ef398e41c36383408c39fd743be41c55a1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Aug 2016 22:22:40 -0700 Subject: [PATCH 1/5] test/sharness: Add sharness v1.0.0 as a submodule It's GPLv2+ [1], so using a submodule keeps the separation from our Apache 2.0 source clear. And it's an isolated enough dependency that I prefer to keep the Git histories separate. Generated with: $ mkdir test $ git submodule add git://github.com/mlafeldt/sharness.git test/sharness $ (cd test/sharness && git checkout v1.0.0) $ git add test/sharness $ cd test $ ln -s sharness/aggregate-results.sh $ ln -s sharness/sharness.sh $ ln -s sharness/test/Makefile $ emacs README.md $ git add README.md Makefile sharness.sh aggregate-results.sh [1]: https://github.com/mlafeldt/sharness/tree/v1.0.0#license Signed-off-by: W. Trevor King --- .gitmodules | 3 +++ test/Makefile | 1 + test/README.md | 22 ++++++++++++++++++++++ test/aggregate-results.sh | 1 + test/sharness | 1 + test/sharness.sh | 1 + 6 files changed, 29 insertions(+) create mode 100644 .gitmodules create mode 120000 test/Makefile create mode 100644 test/README.md create mode 120000 test/aggregate-results.sh create mode 160000 test/sharness create mode 120000 test/sharness.sh 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/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..b02963281 --- /dev/null +++ b/test/README.md @@ -0,0 +1,22 @@ +# 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]). + +[prove]: http://perldoc.perl.org/prove.html +[Sharness]: http://mlafeldt.github.io/sharness/ +[submodule]: http://git-scm.com/docs/git-submodule 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.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 From aa462673303f51f9cd0893a86f35333528d24e07 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Aug 2016 22:45:30 -0700 Subject: [PATCH 2/5] test/t0001-oci-runtime-tool.t: Test --help and --version Signed-off-by: W. Trevor King --- test/README.md | 15 +++++++++++++++ test/sharness.d/posix-utilities.sh | 6 ++++++ test/t0001-oci-runtime-tool.t | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 test/sharness.d/posix-utilities.sh create mode 100755 test/t0001-oci-runtime-tool.t diff --git a/test/README.md b/test/README.md index b02963281..b2a09bc5f 100644 --- a/test/README.md +++ b/test/README.md @@ -17,6 +17,21 @@ Run the tests with: And read the `Makefile` source to find other useful targets (e.g. [`prove`][prove]). +## Naming + +0 - Global `oci-runtime-tool` options. + +## Dependencies + +* [GNU Core Utilities][coreutils] for [`cat`][cat.1], + [`echo`][echo.1], [`head`][head.1], and [`sed][sed.1]. + +[coreutils]: http://www.gnu.org/software/coreutils/coreutils.html [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 +[sed.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html 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/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 From 4f96bb30b776855485870fce2bf828736c9d44e3 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Aug 2016 22:54:00 -0700 Subject: [PATCH 3/5] test/t1000-generate-output.t: Tests generate and --output Signed-off-by: W. Trevor King --- test/README.md | 2 ++ test/t1000-generate-output.t | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 test/t1000-generate-output.t diff --git a/test/README.md b/test/README.md index b2a09bc5f..0aaabea9c 100644 --- a/test/README.md +++ b/test/README.md @@ -21,6 +21,8 @@ And read the `Makefile` source to find other useful targets 0 - Global `oci-runtime-tool` options. +1 - `oci-runtime-tool generate`. + ## Dependencies * [GNU Core Utilities][coreutils] for [`cat`][cat.1], 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 From 3cda91b7b34b253fa7395669d667fe508fb94bdc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Aug 2016 23:07:23 -0700 Subject: [PATCH 4/5] test/t1001-generate-template.t: Add --template tests Using jq to format the output so we don't have to worry about oci-runtime-tool's default tab indents or lack of trailing newlines, neither of which play nicely with <<-EOF here documents. Signed-off-by: W. Trevor King --- test/README.md | 3 ++ test/sharness.d/miscellaneous.sh | 3 ++ test/t1001-generate-template.t | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/sharness.d/miscellaneous.sh create mode 100755 test/t1001-generate-template.t diff --git a/test/README.md b/test/README.md index 0aaabea9c..c1df1a88d 100644 --- a/test/README.md +++ b/test/README.md @@ -27,8 +27,10 @@ And read the `Makefile` source to find other useful targets * [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 @@ -36,4 +38,5 @@ And read the `Makefile` source to find other useful targets [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/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/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 From 11deb9dfe49ec98beb9f5e64491027906de6fac3 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 2 Aug 2016 23:18:00 -0700 Subject: [PATCH 5/5] .travis.yml: Run the sharness tests Signed-off-by: W. Trevor King --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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