mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
tests/int/spec.bats: simplify
Most of whatever is happening in the test cases is already available in setup_hello and teardown_hello. Use these. Rewrite the validation test to be more compact and not dependent on `pwd` value. Also, pinning xeipuuv/gojsonschema to a particular version is no longer required. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
+18
-79
@@ -3,99 +3,38 @@
|
||||
load helpers
|
||||
|
||||
function setup() {
|
||||
# initial cleanup in case a prior test exited and did not cleanup
|
||||
rm -rf "$HELLO_BUNDLE"
|
||||
|
||||
# setup hello-world for spec generation testing
|
||||
mkdir -p "$HELLO_BUNDLE"/rootfs
|
||||
tar -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
|
||||
setup_hello
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
rm -rf "$HELLO_BUNDLE"
|
||||
teardown_hello
|
||||
}
|
||||
|
||||
@test "spec generation cwd" {
|
||||
cd "$HELLO_BUNDLE"
|
||||
# note this test runs from the bundle not the integration root
|
||||
|
||||
# test that config.json does not exist after the above partial setup
|
||||
[ ! -e config.json ]
|
||||
|
||||
# test generation of spec does not return an error
|
||||
runc_spec
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# test generation of spec created our config.json (spec)
|
||||
[ -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"* ]]
|
||||
|
||||
# change the default args parameter from sh to hello
|
||||
update_config '(.. | select(.? == "sh")) |= "/hello"'
|
||||
|
||||
# ensure the generated spec works by running hello-world
|
||||
runc run test_hello
|
||||
[ "$status" -eq 0 ]
|
||||
runc run test_hello
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "spec generation --bundle" {
|
||||
# note this test runs from the integration root not the bundle
|
||||
|
||||
# test that config.json does not exist after the above partial setup
|
||||
[ ! -e "$HELLO_BUNDLE"/config.json ]
|
||||
|
||||
# test generation of spec does not return an error
|
||||
runc_spec "$HELLO_BUNDLE"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# test generation of spec created our config.json (spec)
|
||||
[ -e "$HELLO_BUNDLE"/config.json ]
|
||||
|
||||
# change the default args parameter from sh to hello
|
||||
update_config '(.. | select(.? == "sh")) |= "/hello"' "$HELLO_BUNDLE"
|
||||
|
||||
# ensure the generated spec works by running hello-world
|
||||
runc run --bundle "$HELLO_BUNDLE" test_hello
|
||||
[ "$status" -eq 0 ]
|
||||
runc run --bundle "$HELLO_BUNDLE" test_hello
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "spec validator" {
|
||||
requires rootless_no_features
|
||||
requires rootless_no_features
|
||||
|
||||
TESTDIR=$(pwd)
|
||||
cd "$HELLO_BUNDLE"
|
||||
SPEC_VERSION=$(awk '$1 == "github.com/opencontainers/runtime-spec" {print $2}' "$BATS_TEST_DIRNAME"/../../go.mod)
|
||||
# Will look like this when not pinned to specific tag: "v0.0.0-20190207185410-29686dbc5559", otherwise "v1.0.0"
|
||||
SPEC_COMMIT=$(cut -d "-" -f 3 <<< "$SPEC_VERSION")
|
||||
SPEC_REF=$([[ -z "$SPEC_COMMIT" ]] && echo "$SPEC_VERSION" || echo "$SPEC_COMMIT")
|
||||
|
||||
run git clone https://github.com/opencontainers/runtime-spec.git src/runtime-spec
|
||||
[ "$status" -eq 0 ]
|
||||
git clone https://github.com/opencontainers/runtime-spec.git
|
||||
( cd runtime-spec && git reset --hard "$SPEC_REF" )
|
||||
SCHEMA='runtime-spec/schema/config-schema.json'
|
||||
[ -e "$SCHEMA" ]
|
||||
|
||||
SPEC_VERSION=$(grep 'github.com/opencontainers/runtime-spec' "${TESTDIR}"/../../go.mod | cut -d ' ' -f 2)
|
||||
go get github.com/xeipuuv/gojsonschema
|
||||
go build runtime-spec/schema/validate.go
|
||||
|
||||
# Will look like this when not pinned to spesific tag: "v0.0.0-20190207185410-29686dbc5559", otherwise "v1.0.0"
|
||||
SPEC_COMMIT=$(cut -d "-" -f 3 <<< "$SPEC_VERSION")
|
||||
|
||||
SPEC_REF=$([[ -z "$SPEC_COMMIT" ]] && echo "$SPEC_VERSION" || echo "$SPEC_COMMIT")
|
||||
|
||||
run bash -c "cd src/runtime-spec && git reset --hard ${SPEC_REF}"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[ -e src/runtime-spec/schema/config-schema.json ]
|
||||
|
||||
run bash -c "GOPATH='$GOPATH' go get github.com/xeipuuv/gojsonschema"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run bash -c "cd ${GOPATH}/src/github.com/xeipuuv/gojsonschema && git reset --hard 6637feb73ee44cd4640bb3def285c29774234c7f"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
GOPATH="$GOPATH" go build src/runtime-spec/schema/validate.go
|
||||
[ -e ./validate ]
|
||||
|
||||
runc spec
|
||||
[ -e config.json ]
|
||||
|
||||
run ./validate src/runtime-spec/schema/config-schema.json config.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${lines[0]}" == *"The document is valid"* ]]
|
||||
./validate "$SCHEMA" config.json
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user