2016-03-15 03:55:05 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
# initial cleanup in case a prior test exited and did not cleanup
|
|
|
|
cd "$INTEGRATION_ROOT"
|
|
|
|
run rm -f -r "$HELLO_BUNDLE"
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# setup hello-world for spec generation testing
|
2016-05-16 16:21:52 +08:00
|
|
|
run mkdir "$HELLO_BUNDLE"
|
2016-03-15 03:55:05 +08:00
|
|
|
run mkdir "$HELLO_BUNDLE"/rootfs
|
|
|
|
run tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
cd "$INTEGRATION_ROOT"
|
|
|
|
run rm -f -r "$HELLO_BUNDLE"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "spec generation cwd" {
|
|
|
|
cd "$HELLO_BUNDLE"
|
|
|
|
# note this test runs from the bundle not the integration root
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# test that config.json does not exist after the above partial setup
|
2016-03-15 03:55:05 +08:00
|
|
|
[ ! -e config.json ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# test generation of spec does not return an error
|
2016-05-11 15:45:00 +08:00
|
|
|
runc_spec
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# test generation of spec created our config.json (spec)
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e config.json ]
|
|
|
|
|
|
|
|
# test existence of required args parameter in the generated config.json
|
|
|
|
run bash -c "grep -A2 'args' config.json | grep 'sh'"
|
|
|
|
[[ "${output}" == *"sh"* ]]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# change the default args parameter from sh to hello
|
|
|
|
sed -i 's;"sh";"/hello";' config.json
|
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# ensure the generated spec works by running hello-world
|
|
|
|
runc run test_hello
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "spec generation --bundle" {
|
2016-05-16 16:21:52 +08:00
|
|
|
# note this test runs from the integration root not the bundle
|
|
|
|
|
|
|
|
# test that config.json does not exist after the above partial setup
|
2016-03-15 03:55:05 +08:00
|
|
|
[ ! -e "$HELLO_BUNDLE"/config.json ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# test generation of spec does not return an error
|
2017-09-07 07:54:46 +08:00
|
|
|
runc_spec "$HELLO_BUNDLE"
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
|
|
|
# test generation of spec created our config.json (spec)
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e "$HELLO_BUNDLE"/config.json ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
# change the default args parameter from sh to hello
|
|
|
|
sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json
|
|
|
|
|
2016-05-14 06:49:45 +08:00
|
|
|
# ensure the generated spec works by running hello-world
|
|
|
|
runc run --bundle "$HELLO_BUNDLE" test_hello
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "spec validator" {
|
2016-06-10 03:03:11 +08:00
|
|
|
TESTDIR=$(pwd)
|
2016-03-15 03:55:05 +08:00
|
|
|
cd "$HELLO_BUNDLE"
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-04-26 15:59:00 +08:00
|
|
|
run git clone https://github.com/opencontainers/runtime-spec.git src/runtime-spec
|
2016-06-10 03:03:11 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2017-04-15 15:31:39 +08:00
|
|
|
SPEC_COMMIT=$(grep '^github.com/opencontainers/runtime-spec' ${TESTDIR}/../../vendor.conf | cut -d ' ' -f 2)
|
2017-02-23 07:02:13 +08:00
|
|
|
run git -C src/runtime-spec reset --hard "${SPEC_COMMIT}"
|
|
|
|
|
2016-06-10 03:03:11 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-09-12 07:48:12 +08:00
|
|
|
[ -e src/runtime-spec/schema/config-schema.json ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-03-15 03:55:05 +08:00
|
|
|
run bash -c "GOPATH='$GOPATH' go get github.com/xeipuuv/gojsonschema"
|
|
|
|
[ "$status" -eq 0 ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2018-01-04 23:11:45 +08:00
|
|
|
run git -C "${GOPATH}/src/github.com/xeipuuv/gojsonschema" reset --hard 6637feb73ee44cd4640bb3def285c29774234c7f
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2016-04-26 15:59:00 +08:00
|
|
|
GOPATH="$GOPATH" go build src/runtime-spec/schema/validate.go
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e ./validate ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-05-09 21:06:42 +08:00
|
|
|
runc spec
|
2016-03-15 03:55:05 +08:00
|
|
|
[ -e config.json ]
|
2016-05-16 16:21:52 +08:00
|
|
|
|
2016-09-12 07:48:12 +08:00
|
|
|
run ./validate src/runtime-spec/schema/config-schema.json config.json
|
2016-03-15 03:55:05 +08:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${lines[0]}" == *"The document is valid"* ]]
|
|
|
|
}
|