Skip to content

Commit

Permalink
Add E2E tests for all built-in checks (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy committed Nov 9, 2021
1 parent 0db0f5f commit 8231fb5
Show file tree
Hide file tree
Showing 49 changed files with 2,462 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/bats-e2e.yaml
@@ -0,0 +1,44 @@
name: Test kube-linter via BATS

on:
- pull_request
- push

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Checkout all repo history to make tags available for figuring out kube-linter version during build.
fetch-depth: 0

- name: Read Go version from go.mod
run: echo "GO_VERSION=$(grep -E "^go\s+[0-9.]+$" go.mod | cut -d " " -f 2)" >> $GITHUB_ENV

- name: Setup Go environment
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build binaries
run: make build

- name: Print kube-linter version
run: .gobin/kube-linter version

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.5.0

- name: Run bats tests
run: make e2e-bats
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@
# Empty file touched by `make deps`
/deps

e2etests/test_helper
8 changes: 8 additions & 0 deletions Makefile
Expand Up @@ -108,3 +108,11 @@ test:
e2e-test: $(KUBE_LINTER_BIN)
KUBE_LINTER_BIN="$(KUBE_LINTER_BIN)" go test -tags e2e -count=1 ./e2etests/...

.PHONY: e2e-bats
e2e-bats: $(KUBE_LINTER_BIN)
@command -v jq &> /dev/null || { echo >&2 'ERROR: jq not installed; See: https://stedolan.github.io/jq/download - Aborting'; exit 1; }
@command -v diff &> /dev/null || { echo >&2 'ERROR: diff not installed; See: https://www.baeldung.com/linux/diff-command - Aborting'; exit 1; }
@command -v bats &> /dev/null || { echo >&2 'ERROR: bats not installed; See: https://bats-core.readthedocs.io/en/stable/installation.html - Aborting'; exit 1; }

KUBE_LINTER_BIN="$(KUBE_LINTER_BIN)" e2etests/bats-tests.sh
KUBE_LINTER_BIN="$(KUBE_LINTER_BIN)" e2etests/check-bats-tests.sh
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -63,6 +63,27 @@ Installing KubeLinter from source is as simple as following these steps:
.gobin/kube-linter version
```

### Testing KubeLinter
There are several layers of testing. Each layer is expected to pass.

1. `go` unit tests:

```bash
make test
```

2. end-to-end integration tests:

```bash
make e2e-test
```

3. and finally, end-to-end integration tests using `bats-core`:

```bash
make e2e-bats
```

## Using KubeLinter

### Local YAML Linting
Expand Down
9 changes: 9 additions & 0 deletions e2etests/bats-support-clone.bash
@@ -0,0 +1,9 @@
if [[ ! -d "e2etests/test_helper/bats-support" ]]; then
# Download bats-support dynamically so it doesnt need to be added into source
git clone https://github.com/ztombol/bats-support e2etests/test_helper/bats-support --depth 1
fi

if [[ ! -d "e2etests/test_helper/redhatcop-bats-library" ]]; then
# Download redhat-cop/bats-library dynamically so it doesnt need to be added into source
git clone https://github.com/redhat-cop/bats-library e2etests/test_helper/redhatcop-bats-library --depth 1
fi

0 comments on commit 8231fb5

Please sign in to comment.