Skip to content

Commit dd0e053

Browse files
committed
test/t1001-generate-template.t: Add --template tests
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 <[email protected]>
1 parent 0156c14 commit dd0e053

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

test/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ And read the `Makefile` source to find other useful targets
2727

2828
* [GNU Core Utilities][coreutils] for [`cat`][cat.1],
2929
[`echo`][echo.1], and [`head`][head.1].
30+
* [jq] for [`jq`][jq.1].
3031

3132
[coreutils]: http://www.gnu.org/software/coreutils/coreutils.html
33+
[jq]: https://stedolan.github.io/jq/
3234
[prove]: http://perldoc.perl.org/prove.html
3335
[Sharness]: http://mlafeldt.github.io/sharness/
3436
[submodule]: http://git-scm.com/docs/git-submodule
3537

3638
[cat.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cat.html
3739
[echo.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
3840
[head.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html
41+
[jq.1]: https://stedolan.github.io/jq/manual/

test/sharness.d/miscellaneous.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
command -v jq >/dev/null 2>/dev/null && test_set_prereq JQ
2+
3+
true

test/t1001-generate-template.t

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
test_description='Test generate template'
4+
5+
. ./sharness.sh
6+
7+
test_expect_failure CAT,ECHO,HEAD,JQ 'Test ocitools generate --template with an empty template' "
8+
echo '{}' >template &&
9+
ocitools generate --template template | jq . >actual &&
10+
cat <<-EOF >expected &&
11+
{
12+
\"ociVersion\": \"1.0.0-rc1\",
13+
\"platform\": {
14+
\"os\": \"linux\",
15+
\"arch\": \"amd64\"
16+
},
17+
\"process\": {
18+
\"user\": {
19+
\"uid\": 0,
20+
\"gid\": 0
21+
},
22+
\"args\": null,
23+
\"cwd\": \"/\"
24+
},
25+
\"root\": {
26+
\"path\": \"rootfs\"
27+
}
28+
}
29+
EOF
30+
test_cmp expected actual
31+
"
32+
33+
test_expect_failure CAT,HEAD,JQ 'Test ocitools generate --template with a version' "
34+
echo '{\"ociVersion\": \"0.9.0\"}' >template &&
35+
ocitools generate --template template | jq . >actual &&
36+
cat <<-EOF >expected &&
37+
{
38+
\"ociVersion\": \"0.9.0\",
39+
\"platform\": {
40+
\"os\": \"linux\",
41+
\"arch\": \"amd64\"
42+
},
43+
\"process\": {
44+
\"user\": {
45+
\"uid\": 0,
46+
\"gid\": 0
47+
},
48+
\"args\": null,
49+
\"cwd\": \"/\"
50+
},
51+
\"root\": {
52+
\"path\": \"rootfs\"
53+
}
54+
}
55+
EOF
56+
test_cmp expected actual
57+
"
58+
59+
test_done

0 commit comments

Comments
 (0)