Skip to content

Commit

Permalink
test/t1001-generate-template.t: Add --template tests
Browse files Browse the repository at this point in the history
Using jq to format the output so we don't have to worry about
ocitools' default tab indents or lack of trailing newlines, neither of
which play nicely with <<-EOF here documents.

The tests are known failures, because runtime-spec v1.0.0-rc1 lacks
good omitempty handling.

  $ ocitools generate --template <(echo '{}')
  …
    "hooks": {},
    "linux": {},
    "solaris": {
      "cappedCPU": {},
      "cappedMemory": {}
    }
  }

These issues are addressed by the in-flight [1,2], although their late
landings in runtime-spec mean we'll never be able to address them in
the v1.0.0.rc1 branch of ocitools.

[1]: opencontainers/runtime-spec#427
     Subject: config: Explicitly list 'hooks' as optional
[2]: opencontainers#112
     Subject: generate: Adjust to Spec.Linux being a pointer

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Aug 3, 2016
1 parent 0156c14 commit dd0e053
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ And read the `Makefile` source to find other useful targets

* [GNU Core Utilities][coreutils] for [`cat`][cat.1],
[`echo`][echo.1], and [`head`][head.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/
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
59 changes: 59 additions & 0 deletions test/t1001-generate-template.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh

test_description='Test generate template'

. ./sharness.sh

test_expect_failure CAT,ECHO,HEAD,JQ 'Test ocitools generate --template with an empty template' "
echo '{}' >template &&
ocitools generate --template template | jq . >actual &&
cat <<-EOF >expected &&
{
\"ociVersion\": \"1.0.0-rc1\",
\"platform\": {
\"os\": \"linux\",
\"arch\": \"amd64\"
},
\"process\": {
\"user\": {
\"uid\": 0,
\"gid\": 0
},
\"args\": null,
\"cwd\": \"/\"
},
\"root\": {
\"path\": \"rootfs\"
}
}
EOF
test_cmp expected actual
"

test_expect_failure CAT,HEAD,JQ 'Test ocitools generate --template with a version' "
echo '{\"ociVersion\": \"0.9.0\"}' >template &&
ocitools generate --template template | jq . >actual &&
cat <<-EOF >expected &&
{
\"ociVersion\": \"0.9.0\",
\"platform\": {
\"os\": \"linux\",
\"arch\": \"amd64\"
},
\"process\": {
\"user\": {
\"uid\": 0,
\"gid\": 0
},
\"args\": null,
\"cwd\": \"/\"
},
\"root\": {
\"path\": \"rootfs\"
}
}
EOF
test_cmp expected actual
"

test_done

0 comments on commit dd0e053

Please sign in to comment.