Skip to content

Commit

Permalink
schema: Add 'test' target to the Makefile
Browse files Browse the repository at this point in the history
And fill in some known-good and known-bad examples.  We can make this
as detailed as we want, but this commit just adds enough to know that:

* The full-file spec examples are valid.
* The JSON Schema can distinguish valid examples from invalid JSON.

This will help catch JSON Schema typos like those being addressed by
[1].

[1]: opencontainers#784

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Apr 27, 2017
1 parent 13895d6 commit 2e9bf5f
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ script:
- echo "${TRAVIS_COMMIT_RANGE} -> ${TRAVIS_COMMIT_RANGE/.../..} (travis-ci/travis-ci#4596)"
- TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../..}" make .gitvalidation
- make docs
- make -C schema test
21 changes: 20 additions & 1 deletion schema/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GOOD_TESTS = $(wildcard test/good/*.json)
BAD_TESTS = $(wildcard test/bad/*.json)

.PHONY: default
default: validate
Expand All @@ -12,13 +14,30 @@ help:

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

.PHONY: validate
validate: validate.go
go get -d ./...
go build ./validate.go

.PHONY: test
test: validate $(TESTS)
for TYPE in $$(ls test); \
do \
echo "testing $${TYPE}"; \
for FILE in $$(ls "test/$${TYPE}/good"); \
do \
echo " testing test/$${TYPE}/good/$${FILE}"; \
./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}"; \
done; \
for FILE in $$(ls "test/$${TYPE}/bad"); \
do \
echo " testing test/$${TYPE}/bad/$${FILE}"; \
! ./validate "$${TYPE}-schema.json" "test/$${TYPE}/bad/$${FILE}"; \
done; \
done

.PHONY: clean
clean:
rm -f validate
1 change: 1 addition & 0 deletions schema/test/config/bad/invalid-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{]
18 changes: 18 additions & 0 deletions schema/test/config/good/minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ociVersion": "1.0.0",
"platform": {
"os": "linux",
"arch": "amd64"
},
"root": {
"path": "rootfs"
},
"process": {
"cwd": "/",
"args": ["sh"],
"user": {
"uid": 0,
"gid": 0
}
}
}
Loading

0 comments on commit 2e9bf5f

Please sign in to comment.