Skip to content

Commit

Permalink
Add CircleCI config for testing
Browse files Browse the repository at this point in the history
This includes modifying the acceptance tests to use the local rather
than global version of Kubeval.
  • Loading branch information
garethr committed Jul 20, 2019
1 parent 13b5089 commit 34cdb22
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
65 changes: 65 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: 2.1
orbs:
snyk: garethr/[email protected]
jobs:
build:
docker:
- image: circleci/golang:1.12-node

steps:
- checkout
- restore_cache:
keys:
- go-mod-{{ checksum "go.sum" }}
- run: make test
- run:
name: Build binary
command: make build
- save_cache:
key: go-mod-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Install Bats
command: |
cd /tmp
curl -L https://github.com/sstephenson/bats/archive/v0.4.0.tar.gz | tar -xz
sudo ./bats-0.4.0/install.sh /usr/local
- snyk/install_snyk
- run:
name: Run acceptance tests
command: |
sudo npm install tap-xunit -g
mkdir -p ~/reports
bats acceptance.bats --tap | tap-xunit > ~/reports/kubeval.xml
- snyk/check_code_with_snyk:
args: --file=go.mod
- store_test_results:
path: ~/reports
- store_artifacts:
path: ~/reports
image:
docker:
- image: circleci/buildpack-deps:stretch

steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
version: 18.09.3
- snyk/install_snyk
- run:
name: Build image
command: docker build --progress plain -t garethr/kubeval .
environment:
DOCKER_BUILDKIT: 1
- snyk/check_docker_with_snyk:
image: garethr/kubeval
project: docker.io/garethr/kubeval

workflows:
version: 2
build:
jobs:
- build
- image
2 changes: 1 addition & 1 deletion Dockerfile.acceptance
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN make build

FROM bats/bats:v1.1.0
RUN apk --no-cache add ca-certificates
COPY --from=builder /bin/kubeval /usr/local/bin
COPY --from=builder /bin/kubeval /bin/kubeval
COPY acceptance.bats /acceptance.bats
COPY fixtures /fixtures
RUN "/acceptance.bats"
42 changes: 21 additions & 21 deletions acceptance.bats
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
#!/usr/bin/env bats

@test "Pass when parsing a valid Kubernetes config YAML file" {
run kubeval fixtures/valid.yaml
run bin/kubeval fixtures/valid.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/valid.yaml contains a valid ReplicationController" ]
}

@test "Pass when parsing a valid Kubernetes config YAML file on stdin" {
run bash -c "cat fixtures/valid.yaml | kubeval"
run bash -c "cat fixtures/valid.yaml | bin/kubeval"
[ "$status" -eq 0 ]
[ "$output" = "The file stdin contains a valid ReplicationController" ]
}

@test "Pass when parsing a valid Kubernetes config YAML file explicitly on stdin" {
run bash -c "cat fixtures/valid.yaml | kubeval -"
run bash -c "cat fixtures/valid.yaml | bin/kubeval -"
[ "$status" -eq 0 ]
[ "$output" = "The file stdin contains a valid ReplicationController" ]
}

@test "Pass when parsing a valid Kubernetes config JSON file" {
run kubeval fixtures/valid.json
run bin/kubeval fixtures/valid.json
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/valid.json contains a valid Deployment" ]
}

@test "Pass when parsing a Kubernetes file with string and integer quantities" {
run kubeval fixtures/quantity.yaml
run bin/kubeval fixtures/quantity.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/quantity.yaml contains a valid LimitRange" ]
}

@test "Pass when parsing a valid Kubernetes config file with int_to_string vars" {
run kubeval fixtures/int_or_string.yaml
run bin/kubeval fixtures/int_or_string.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/int_or_string.yaml contains a valid Service" ]
}

@test "Pass when parsing a valid Kubernetes config file with null arrays" {
run kubeval fixtures/null_array.yaml
run bin/kubeval fixtures/null_array.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/null_array.yaml contains a valid Deployment" ]
}

@test "Pass when parsing a valid Kubernetes config file with null strings" {
run kubeval fixtures/null_string.yaml
run bin/kubeval fixtures/null_string.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/null_string.yaml contains a valid Service" ]
}

@test "Pass when parsing a multi-document config file" {
run kubeval fixtures/multi_valid.yaml
run bin/kubeval fixtures/multi_valid.yaml
[ "$status" -eq 0 ]
}

@test "Fail when parsing a multi-document config file with one invalid resource" {
run kubeval fixtures/multi_invalid.yaml
run bin/kubeval fixtures/multi_invalid.yaml
[ "$status" -eq 1 ]
}

@test "Fail when parsing an invalid Kubernetes config file" {
run kubeval fixtures/invalid.yaml
run bin/kubeval fixtures/invalid.yaml
[ "$status" -eq 1 ]
}

@test "Fail when parsing an invalid Kubernetes config file on stdin" {
run bash -c "cat fixtures/invalid.yaml | kubeval"
run bash -c "cat fixtures/invalid.yaml | bin/kubeval -"
[ "$status" -eq 1 ]
}

@test "Return relevant error for non-existent file" {
run kubeval fixtures/not-here
run bin/kubeval fixtures/not-here
[ "$status" -eq 1 ]
[ $(expr "$output" : "^Could not open file") -ne 0 ]
}

@test "Pass when parsing a blank config file" {
run kubeval fixtures/blank.yaml
run bin/kubeval fixtures/blank.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/blank.yaml contains an empty YAML document" ]
}

@test "Pass when parsing a blank config file with a comment" {
run kubeval fixtures/comment.yaml
run bin/kubeval fixtures/comment.yaml
[ "$status" -eq 0 ]
[ "$output" = "The file fixtures/comment.yaml contains an empty YAML document" ]
}

@test "Return relevant error for YAML missing kind key" {
run kubeval fixtures/missing_kind.yaml
run bin/kubeval fixtures/missing_kind.yaml
[ "$status" -eq 1 ]
}

@test "Fail when parsing a config with additional properties and strict set" {
run kubeval --strict fixtures/extra_property.yaml
run bin/kubeval --strict fixtures/extra_property.yaml
[ "$status" -eq 1 ]
}

@test "Fail when parsing a config with a kind key but no value" {
run kubeval fixtures/missing_kind_value.yaml
run bin/kubeval fixtures/missing_kind_value.yaml
[ "$status" -eq 1 ]
}

@test "Pass when parsing a config with additional properties" {
run kubeval fixtures/extra_property.yaml
run bin/kubeval fixtures/extra_property.yaml
[ "$status" -eq 0 ]
}

@test "Fail when parsing a config with CRD" {
run kubeval fixtures/test_crd.yaml
run bin/kubeval fixtures/test_crd.yaml
[ "$status" -eq 1 ]
}

@test "Pass when parsing a config with CRD and ignoring missing schemas" {
run kubeval --ignore-missing-schemas fixtures/test_crd.yaml
run bin/kubeval --ignore-missing-schemas fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}

0 comments on commit 34cdb22

Please sign in to comment.