Skip to content

Commit bd69960

Browse files
authored
enable test coverage + upload results in workflow (#91)
* enable test coverage + upload results in workflow * add generated artifacts to .gitignore * Update test README
1 parent b420dad commit bd69960

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

.github/workflows/go.yml

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ jobs:
4545
4646
- name: Run Go Tests
4747
run: make test
48+
49+
- name: Upload Test Coverage results
50+
uses: actions/upload-artifact@v2
51+
with:
52+
name: lib-test-coverage-html
53+
path: tests/v2/lib-test-coverage.html

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ main
2323

2424
# File created running tests
2525
tests/**/tmp/
26+
tests/v2/lib-test-coverage.*
27+
2628

2729
# Mac related files
2830
.DS_Store

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ bin:
1919

2020
.PHONY: test
2121
test:
22-
go test ./...
22+
go test -coverprofile tests/v2/lib-test-coverage.out -v ./...
23+
go tool cover -html=tests/v2/lib-test-coverage.out -o tests/v2/lib-test-coverage.html
2324

2425
.PHONY: clean
2526
clean:

tests/README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## About
44

5-
The tests use the go language and are intended to test every apsect of the parser for every schema attribute. Some basic aspects of the tests:
5+
The tests use the go language and are intended to test every aspect of the parser for every schema attribute. Some basic aspects of the tests:
66

77
* A first test (parser_v200_schema_test.go) feeds pre-created devfiles to the parser to ensure the parser can parse all attribues and return an appropriate error when the devfile contains an error. This test is not currently available.
88
* A second set of tests (parser_v200_verify_test.go) create devfile content at runtime:
@@ -35,23 +35,32 @@ The tests which generate devfiles with random content at run time currently cove
3535
## Test structure
3636

3737
* From this repository
38-
- `test/v2/libraryTest/library-test.go`: The go unit test program
39-
- `test/v2/utils/library/*-utils.go` : utilites, used by the test, which contain functions uniqiue to the library tests. Mostly contain the code to modify and check devfile content.
38+
- `tests/v2/libraryTest/library-test.go`: The go unit test program
39+
- `tests/v2/utils/library/*-utils.go` : utilites, used by the test, which contain functions uniqiue to the library tests. Mostly contain the code to modify and check devfile content.
4040
* From the [api respository](https://github.com/devfile/api/tree/master/test/v200/utils/common)
41-
- `test/v200/utils/common/*-utils.go` : utilites, used by the test, which are also used by the api tests. Mostly contain the code to generate valid devfile content.
41+
- `tests/v200/utils/common/*-utils.go` : utilites, used by the test, which are also used by the api tests. Mostly contain the code to generate valid devfile content.
4242

43-
## Running the tests
43+
## Running the tests locally
4444

45-
1. Go to directory /tests/v2/libraryTest
46-
1. Run ```go test``` or ```go test -v```
45+
1. Go to the ```/library``` directory
46+
1. Run ```Make test```
4747
1. The test creates the following files:
4848
1. ```./tmp/test.log``` contains log output from the tests.
4949
1. ```./tmp/library_test/Test_*.yaml``` are the devfiles which are randomly generated at runtime. The file name matches the name of the test function which resulted in them being created.
5050
1. If a test detects an error when comparing properties returned by the parser with expected properties
5151
* ```./tmp/library_test/Test_*_<property id>_Parser.yaml``` - property as returned by the parser
5252
* ```./tmp/library_test/Test_*_<property id>_Test.yaml``` - property as expected by the test
53+
1. ```tests/v2/lib-test-coverage.html``` which is the test coverage report for the test run. You can open this file up in a browser and inspect the results to determine the gaps you may have in testing
54+
55+
Note: each run of the test removes the existing contents of the ```./tmp``` directory
56+
57+
## Viewing test results from a workflow
58+
59+
The tests run automatically with every PR or Push action. You can see the results in the `devfile/library` repo's `Actions` view:
5360

54-
Note: each run of the test removes the existing conents of the ```./tmp``` directory
61+
1. Select the `Validate PRs` workflow and click on the PR you're interested in
62+
1. To view the console output, select the `Build` job and expand the `Run Go Tests` step. This will give you a summary of the tests that were executed and their respective status
63+
1. To view the test coverage report, click on the `Summary` page and you should see an `Artifacts` section with the `lib-test-coverage-html` file available for download.
5564

5665

5766

0 commit comments

Comments
 (0)