Skip to content

Commit edb6701

Browse files
authored
Enable test coverage + upload results in workflow (#476)
* enable test coverage + upload results in workflow * Update Readme * create a separate step for report generation * fix path
1 parent c00f040 commit edb6701

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

.github/workflows/ci.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ jobs:
3232
run: ./docker-run.sh ./validate-samples.sh
3333

3434
- name: Run GO tests
35-
run: go test -v ./...
35+
run: go test -coverprofile test/v200/api-test-coverage.out -v ./...
36+
37+
- name: Generate test coverage report
38+
run: go tool cover -html=test/v200/api-test-coverage.out -o test/v200/api-test-coverage.html
39+
40+
- name: Upload Test Coverage results
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: api-test-coverage-html
44+
path: test/v200/api-test-coverage.html
45+
3646

3747
- name: Check GO mod state
3848
run: |

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build/_output
33
build/_test
44
test/**/tmp
55
test/go/pkg
6+
test/v200/api-test-coverage.*
67
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
78
### Emacs ###
89
# -*- mode: gitignore; -*-

test/README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ The API tests are intended to provide a comprehensive verification of the devfil
1616
- `test-xxxxxxx.json` : these files are the top level json files, they define the schema to verify and the test files to run.
1717
- `xxxxxx-tests.json` : these are the test files which contain individual tests which provide the yaml snippets to combine and the expected result.
1818

19-
## Running tests
19+
## Running tests locally
2020

21-
from the test/go/src/test directory run
21+
From the `test/v200/schemaTest` directory run
2222
- `go test -v`
2323

2424
The test will read each of the test-xxxxxx.json files and run the tests defined within. The generated .yaml files used for the tests are created in a `tmp/test-xxxxxx/` directory. These files are not deleted when the test finishes so they can be used to assess any errors, however they will be deleted by a subsequent run of the test. Running the test with the -v option ensures you see a full list of passes and failures.
@@ -57,14 +57,26 @@ A new test approach, shared with the library repository for testing valid devfil
5757
- `test/v200/utils/common/*-utils.go` : utilites, used by the test, which are also used by the library tests. Mostly contain the code to generate valid devfile content.
5858

5959

60-
## Running tests
60+
## Running tests locally
6161

6262
from the `test/v200/apiTest/` directory run
6363
- `go test -v`
6464

65-
* The test will generate a set of valid devfile.yaml files in `test/v200/apiTest/tmp/api-test/
65+
* The test will generate a set of valid devfile.yaml files in `test/v200/apiTest/tmp/api-test/`
6666
* The test will generate a log file: `test/v200/apiTest/tmp/test.log`
6767
* Each run of the test removes the `test/v200/apiTest/tmp` directory from the previous run.
6868

69+
# Run test coverage analysis and reporting locally
6970

71+
This is useful to determine if there are any gaps in testing. Run these steps at the root directory `/api` to get a report of all the overall tests, including the ones for api and schema
7072

73+
- `go test -coverprofile test/v200/api-test-coverage.out -v ./...`
74+
- `go tool cover -html=test/v200/api-test-coverage.out -o test/v200/api-test-coverage.html`
75+
76+
## Viewing test results from a workflow
77+
78+
The tests run automatically with every PR or Push action. You can see the results in the `devfile/api` repo's `Actions` view:
79+
80+
1. Select the `CI` workflow and click on the PR you're interested in
81+
1. To view the console output, select the `build-and-validate` job and expand the `Run Go Tests` step. This will give you a summary of the tests that were executed and their respective status
82+
1. To view the test coverage report, click on the `Summary` page and you should see an `Artifacts` section with the `api-test-coverage-html` file available for download.

0 commit comments

Comments
 (0)