Skip to content

Commit 8976b0a

Browse files
Merge pull request #785 from wking/schema-tests
schema: Add 'test' target to the Makefile
2 parents ee87262 + 0b7efd2 commit 8976b0a

File tree

7 files changed

+435
-1
lines changed

7 files changed

+435
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ script:
2222
- echo "${TRAVIS_COMMIT_RANGE} -> ${TRAVIS_COMMIT_RANGE/.../..} (travis-ci/travis-ci#4596)"
2323
- TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../..}" make .gitvalidation
2424
- make docs
25+
- make -C schema test

schema/Makefile

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
GOOD_TESTS = $(wildcard test/good/*.json)
2+
BAD_TESTS = $(wildcard test/bad/*.json)
13

24
.PHONY: default
35
default: validate
@@ -12,13 +14,42 @@ help:
1214

1315
.PHONY: fmt
1416
fmt:
15-
for i in *.json ; do jq --indent 4 -M . "$${i}" > xx && cat xx > "$${i}" && rm xx ; done
17+
find . -name '*.json' -exec bash -c 'jq --indent 4 -M . {} > xx && mv xx {} || echo "skipping invalid {}"' \;
1618

1719
.PHONY: validate
1820
validate: validate.go
1921
go get -d ./...
2022
go build ./validate.go
2123

24+
.PHONY: test
25+
test: validate $(TESTS)
26+
for TYPE in $$(ls test); \
27+
do \
28+
echo "testing $${TYPE}"; \
29+
for FILE in $$(ls "test/$${TYPE}/good"); \
30+
do \
31+
echo " testing test/$${TYPE}/good/$${FILE}"; \
32+
if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \
33+
then \
34+
echo " received expected validation success" ; \
35+
else \
36+
echo " received unexpected validation failure" ; \
37+
exit 1; \
38+
fi \
39+
done; \
40+
for FILE in $$(ls "test/$${TYPE}/bad"); \
41+
do \
42+
echo " testing test/$${TYPE}/bad/$${FILE}"; \
43+
if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \
44+
then \
45+
echo " received unexpected validation success" ; \
46+
exit 1; \
47+
else \
48+
echo " received expected validation failure" ; \
49+
fi \
50+
done; \
51+
done
52+
2253
.PHONY: clean
2354
clean:
2455
rm -f validate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{]

schema/test/config/good/minimal.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"ociVersion": "1.0.0",
3+
"platform": {
4+
"os": "linux",
5+
"arch": "amd64"
6+
},
7+
"root": {
8+
"path": "rootfs"
9+
},
10+
"process": {
11+
"cwd": "/",
12+
"args": ["sh"],
13+
"user": {
14+
"uid": 0,
15+
"gid": 0
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)