Merge pull request #585 from replicatedhq/e2e-test-local

This commit is contained in:
Ethan Mosbaugh
2022-06-02 06:53:55 -07:00
committed by GitHub
4 changed files with 55 additions and 27 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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

33
test/validate-preflight-e2e.sh Executable file
View File

@@ -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