From d3cf4fc7f49fda260c58d8baf0fe4abc710723c4 Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Thu, 2 Jun 2022 13:38:39 +0000 Subject: [PATCH] Run e2e tests locally --- .github/workflows/build-test-deploy.yaml | 27 +------------------ CONTRIBUTING.md | 16 ++++++++++++ Makefile | 6 ++++- test/validate-preflight-e2e.sh | 33 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 27 deletions(-) create mode 100755 test/validate-preflight-e2e.sh diff --git a/.github/workflows/build-test-deploy.yaml b/.github/workflows/build-test-deploy.yaml index 90e74239..a8cd1043 100644 --- a/.github/workflows/build-test-deploy.yaml +++ b/.github/workflows/build-test-deploy.yaml @@ -104,32 +104,7 @@ jobs: name: preflight path: bin/ - run: chmod +x bin/preflight - - run: | - ./bin/preflight --interactive=false --format=json examples/preflight/e2e.yaml > result.json - cat result.json - - EXIT_STATUS=0 - if grep -q "was not collected" result.json; then - echo "Some files were not collected" - EXIT_STATUS=1 - fi - - if (( `jq '.pass | length' result.json` < 1 )); then - echo "No passing preflights found" - EXIT_STATUS=1 - fi - - if (( `jq '.warn | length' result.json` > 0 )); then - echo "Warnings found" - EXIT_STATUS=1 - fi - - if (( `jq '.fail | length' result.json` > 0 )); then - echo "Failed preflights found" - EXIT_STATUS=1 - fi - - exit $EXIT_STATUS + - run: make e2e-test compile-supportbundle: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db22d487..168ea203 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,3 +9,19 @@ Thank you for your interest in Troubleshoot, we welcome your participation. Plea ## Pull Requests If you are interested in contributing a change to the code or documentation please open a pull request with your set of changes. The pull request will be reviewed in a timely manner. + +## Tests + +To run the tests locally run the following: + +```bash +make test +``` + +Additionally, e2e tests can be run with: + +```bash +make support-bundle preflight e2e-test +``` + +A kubernetes cluster as well as `jq` are required to run e2e tests. diff --git a/Makefile b/Makefile index 6a81c789..c11ad6ff 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,14 @@ all: test support-bundle preflight collect ffi: fmt vet go build ${BUILDFLAGS} ${LDFLAGS} -o bin/troubleshoot.so -buildmode=c-shared ffi/main.go -# Run tests +.PHONY: test test: generate fmt vet go test ${BUILDFLAGS} ./pkg/... ./cmd/... -coverprofile cover.out +.PHONY: e2e-test +e2e-test: + ./test/validate-preflight-e2e.sh + .PHONY: support-bundle support-bundle: go build ${BUILDFLAGS} ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot diff --git a/test/validate-preflight-e2e.sh b/test/validate-preflight-e2e.sh new file mode 100755 index 00000000..2d38dadd --- /dev/null +++ b/test/validate-preflight-e2e.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -euo pipefail + +tmpdir="$(mktemp -d)" + +./bin/preflight --interactive=false --format=json examples/preflight/e2e.yaml > "$tmpdir/result.json" +cat "$tmpdir/result.json" + +EXIT_STATUS=0 +if grep -q "was not collected" "$tmpdir/result.json"; then +echo "Some files were not collected" +EXIT_STATUS=1 +fi + +if (( `jq '.pass | length' "$tmpdir/result.json"` < 1 )); then +echo "No passing preflights found" +EXIT_STATUS=1 +fi + +if (( `jq '.warn | length' "$tmpdir/result.json"` > 0 )); then +echo "Warnings found" +EXIT_STATUS=1 +fi + +if (( `jq '.fail | length' "$tmpdir/result.json"` > 0 )); then +echo "Failed preflights found" +EXIT_STATUS=1 +fi + +rm -rf "$tmpdir" + +exit $EXIT_STATUS