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

test: Stub in sharness framework #180

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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/sharness"]
path = test/sharness
url = git://github.com/mlafeldt/sharness.git
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be failed. As from test/README.md, we need do 'git submodule update --init' first. But you didn't do such preparation in travis.yml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... we need do 'git submodule update --init' first.

Travis does that for us.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it.

1 change: 1 addition & 0 deletions test/Makefile
42 changes: 42 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/aggregate-results.sh
1 change: 1 addition & 0 deletions test/sharness
Submodule sharness added at 64595a
3 changes: 3 additions & 0 deletions test/sharness.d/miscellaneous.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
command -v jq >/dev/null 2>/dev/null && test_set_prereq JQ

true
6 changes: 6 additions & 0 deletions test/sharness.d/posix-utilities.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/sharness.sh
22 changes: 22 additions & 0 deletions test/t0001-oci-runtime-tool.t
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions test/t1000-generate-output.t
Original file line number Diff line number Diff line change
@@ -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 <<EOF >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 <<EOF >expected &&
{
\"ociVersion\": \"1.0.0\",
EOF
test_cmp expected actual
"

test_done
51 changes: 51 additions & 0 deletions test/t1001-generate-template.t
Original file line number Diff line number Diff line change
@@ -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