From 1da0c1ceba1e1126f3dc6f42802c50843c6b527e Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Sun, 25 Jun 2023 10:30:04 -0700 Subject: [PATCH] add coverage report for actions tests --- .github/workflows/functional.yml | 19 ++++++++-------- .github/workflows/go.yml | 4 ++-- .gitignore | 1 + runtests.sh | 37 ++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100755 runtests.sh diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 4ffdf7eb..b97ffe08 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -3,7 +3,7 @@ on: pull_request jobs: build: - name: Build + name: RunTests runs-on: ubuntu-latest steps: @@ -16,16 +16,15 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v3 - - name: Get dependencies + - name: Get Dependencies run: | go get -v -t -d ./... - - name: Build - run: make - - - name: Test + - name: Build and Run run: | - mkdir /tmp/gw - ./versitygw -a user -s pass posix /tmp/gw & - sleep 1 - ./versitygw test -a user -s pass -e http://127.0.0.1:7070 full-flow + make testbin + ./runtests.sh + + - name: Coverage Report + run: | + go tool covdata percent -i=/tmp/covdata diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ab379271..f49bb495 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,10 +24,10 @@ jobs: go get -v -t -d ./... - name: Build - run: go build -o versitygw cmd/versitygw/*.go + run: make - name: Test - run: go test -v -timeout 30s -tags=github ./... + run: go test -coverprofile profile.txt -race -v -timeout 30s -tags=github ./... - name: Install govulncheck run: go install golang.org/x/vuln/cmd/govulncheck@latest diff --git a/.gitignore b/.gitignore index e581c1c5..d2365037 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ VERSION *.tar *.tar.gz /rand.data +/profile.txt diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 00000000..a186f36e --- /dev/null +++ b/runtests.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# make temp dirs +mkdir /tmp/gw +rm -rf /tmp/covdata +mkdir /tmp/covdata + +# run server in background +GOCOVERDIR=/tmp/covdata ./versitygw -a user -s pass posix /tmp/gw & +GW_PID=$! + +# wait a second for server to start up +sleep 1 + +# check if server is still running +if ! kill -0 $GW_PID; then + echo "server no longer running" + exit 1 +fi + +# run tests +if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7070 full-flow; then + echo "tests failed" + kill $GW_PID + exit 1 +fi + +# kill off server +kill $GW_PID +exit 0 + +# if the above binary was built with -cover enabled (make testbin), +# then the following can be used for code coverage reports: +# go tool covdata percent -i=/tmp/covdata +# go tool covdata textfmt -i=/tmp/covdata -o profile.txt +# go tool cover -html=profile.txt +