Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: Add 'test' target to the Makefile #785

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 32 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,42 @@ 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}"; \
if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \
then \
echo " received expected validation success" ; \
else \
echo " received unexpected validation failure" ; \
exit 1; \
fi \
done; \
for FILE in $$(ls "test/$${TYPE}/bad"); \
do \
echo " testing test/$${TYPE}/bad/$${FILE}"; \
if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \
then \
echo " received unexpected validation success" ; \
exit 1; \
else \
echo " received expected validation failure" ; \
fi \
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