Run some acceptance tests with network disabled

This commit is contained in:
Yann Hamon 2021-01-09 00:03:14 +01:00
parent 558c364dbc
commit f564719d74
5 changed files with 8323 additions and 12 deletions

View file

@ -1,5 +1,5 @@
FROM bats/bats:v1.2.1
RUN apk --no-cache add ca-certificates parallel
COPY bin/kubeconform /code/bin/
COPY acceptance.bats /code/acceptance.bats
COPY acceptance.bats acceptance-nonetwork.bats /code/
COPY fixtures /code/fixtures

View file

@ -27,6 +27,7 @@ build-bats:
docker-acceptance: build-bats
docker run -t bats -p acceptance.bats
docker run --network none -t bats -p acceptance-nonetwork.bats
release:
docker run -e GITHUB_TOKEN -t -v $$PWD:/go/src/github.com/yannh/kubeconform -w /go/src/github.com/yannh/kubeconform goreleaser/goreleaser:v0.138 goreleaser release --rm-dist

21
acceptance-nonetwork.bats Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bats
@test "Fail when parsing a valid Kubernetes config YAML file without network access" {
run bin/kubeconform fixtures/valid.yaml
[ "$status" -eq 1 ]
}
@test "Pass when parsing a valid config YAML file without network access, with cache" {
run bin/kubeconform -cache fixtures/ fixtures/valid.yaml
[ "$status" -eq 0 ]
}
@test "Pass when parsing a Custom Resource and using a local schema registry with appropriate CRD" {
run bin/kubeconform -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}
@test "Pass when parsing a Custom Resource and specifying several local registries, the last one having the appropriate CRD" {
run bin/kubeconform -schema-location 'fixtures/{{ .ResourceKind }}.json' -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}

View file

@ -1,5 +1,10 @@
#!/usr/bin/env bats
resetCacheFolder() {
rm -rf cache
mkdir -p cache
}
@test "Pass when parsing a valid Kubernetes config YAML file" {
run bin/kubeconform -summary fixtures/valid.yaml
[ "$status" -eq 0 ]
@ -110,16 +115,6 @@
[ "$status" -eq 0 ]
}
@test "Pass when parsing a Custom Resource and using a local schema registry with appropriate CRD" {
run bin/kubeconform -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}
@test "Pass when parsing a Custom Resource and specifying several local registries, the last one having the appropriate CRD" {
run bin/kubeconform -schema-location 'fixtures/{{ .ResourceKind }}.json' -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}
@test "Pass when parsing a config with additional properties" {
run bin/kubeconform -summary fixtures/extra_property.yaml
[ "$status" -eq 0 ]
@ -204,13 +199,21 @@
}
@test "Pass when parsing a valid Kubernetes config YAML file and store cache" {
run mkdir cache
resetCacheFolder
run bin/kubeconform -cache cache -summary fixtures/valid.yaml
[ "$status" -eq 0 ]
[ "$output" = "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0, Skipped: 0" ]
[ "`ls cache/ | wc -l`" -eq 1 ]
}
@test "Fail when no schema found, ensure 404 is not cached on disk" {
resetCacheFolder
run bin/kubeconform -cache cache -schema-location 'https://raw.githubusercontent.com/garethr/openshift-json-schema/master/doesnotexist.json' fixtures/valid.yaml
[ "$status" -eq 1 ]
[ "$output" == 'fixtures/valid.yaml - ReplicationController bob failed validation: could not find schema for ReplicationController' ]
[ "`ls cache/ | wc -l`" -eq 0 ]
}
@test "Fail when cache folder does not exist" {
run bin/kubeconform -cache cache_does_not_exist -summary fixtures/valid.yaml
[ "$status" -eq 1 ]

File diff suppressed because it is too large Load diff