Skip to content

Commit 3cda91b

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 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 <[email protected]>
1 parent 4f96bb3 commit 3cda91b

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

test/README.md

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

2828
* [GNU Core Utilities][coreutils] for [`cat`][cat.1],
2929
[`echo`][echo.1], [`head`][head.1], and [`sed][sed.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/
3942
[sed.1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html

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

0 commit comments

Comments
 (0)