Skip to content

Commit 99db381

Browse files
chore: Integrate coveralls.io
Enable test coverage for unit and integration tests in GHA. Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
1 parent b86312c commit 99db381

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

.github/workflows/tests.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ jobs:
3131
cache-dependency-path: "**/*.sum"
3232
- run: make install-tools
3333
- run: make install-fabric-bins
34-
- run: make unit-tests
34+
- name: unit-tests
35+
env:
36+
GO_TEST_PARAMS: "-race -coverprofile=coverage.profile"
37+
run: make unit-tests
38+
- uses: coverallsapp/github-action@v2
39+
with:
40+
flag-name: utest
41+
parallel: true
3542

3643
utest-postgres:
3744
needs:
@@ -45,18 +52,31 @@ jobs:
4552
cache-dependency-path: "**/*.sum"
4653
- run: make install-tools
4754
- run: make testing-docker-images
48-
- run: make unit-tests-postgres
55+
- name: unit-tests-postgres
56+
env:
57+
GO_TEST_PARAMS: "-race -coverprofile=coverage.profile"
58+
run: make unit-tests-postgres
59+
- uses: coverallsapp/github-action@v2
60+
with:
61+
flag-name: utest-postgres
62+
parallel: true
4963

5064
itest-list:
5165
runs-on: ubuntu-latest
5266
outputs:
5367
tests: ${{ steps.set-itest-tests.outputs.tests }}
68+
all-tests: ${{ steps.set-all-tests.outputs.all-tests }}
5469
steps:
5570
- uses: actions/checkout@v5
5671
- name: list itest targets
5772
id: set-itest-tests
5873
run: |
5974
echo "tests=$(make list-integration-tests | jq -R . | jq -s -c .)" >> $GITHUB_OUTPUT
75+
- name: build carryforward string
76+
id: set-all-tests
77+
run: |
78+
itests=$(make list-integration-tests | sed 's/^/itest-/' | paste -sd "," -)
79+
echo "all-tests=utest,utest-postgres,$itests" >> $GITHUB_OUTPUT
6080
6181
itest:
6282
needs:
@@ -97,4 +117,26 @@ jobs:
97117
make install-softhsm
98118
./ci/scripts/setup_softhsm.sh
99119
100-
- run: make integration-tests-${{ matrix.tests }}
120+
- name: Run the integration test
121+
- run: |
122+
mkdir -p covdata
123+
GOCOVERDIR=covdata \
124+
make integration-tests-${{ matrix.tests }}
125+
go tool covdata textfmt -i=covdata -o coverage.profile
126+
127+
- uses: coverallsapp/github-action@v2
128+
with:
129+
flag-name: itest-${{ matrix.tests }}
130+
parallel: true
131+
132+
finish:
133+
needs:
134+
- utest
135+
- utest-postgres
136+
- itest
137+
runs-on: ubuntu-latest
138+
steps:
139+
- uses: coverallsapp/github-action@v2
140+
with:
141+
parallel-finished: true
142+
carryforward: ${{ needs.itest-list.outputs.all-tests }}

docs/development.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,17 @@ make lint
8787

8888
### Unit Tests
8989

90-
Run all unit tests (with and without race detection):
90+
Run all unit tests:
9191
```bash
9292
make unit-tests
93-
make unit-tests-race
93+
make unit-tests-postgres
94+
make unit-tests-sdk
95+
```
96+
97+
For coverage analysis:
98+
```bash
99+
GO_TEST_PARAMS="-coverprofile=cov.out" make unit-tests
100+
go tool cover -func=cov.out
94101
```
95102

96103
### Integration Tests
@@ -117,6 +124,13 @@ export FSCNODE_PROFILER=true
117124
make integration-tests-fabric-iou
118125
```
119126

127+
Enable coverage profiling:
128+
```bash
129+
mkdir -p covdata
130+
GOCOVERDIR=covdata make integration-tests
131+
go tool covdata textfmt -i=covdata -o profile.txt
132+
```
133+
120134
## Write your own integration test
121135

122136
Creating a new integration test is straightforward.

integration/integration.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ func New(startPort int, path string, topologies ...api.Topology) (*Infrastructur
8585
}
8686
}
8787

88-
buildServer := common.NewBuildServer("-tags", "pkcs11")
88+
// build parameter
89+
var params []string
90+
params = append(params, "-tags", "pkcs11")
91+
92+
// build with coverage profiling, more details: https://go.dev/doc/build-cover
93+
if _, ok := os.LookupEnv("GOCOVERDIR"); ok {
94+
params = append(params, "-cover")
95+
}
96+
97+
buildServer := common.NewBuildServer(params...)
8998
buildServer.Serve()
9099
builder := buildServer.Client()
91100

0 commit comments

Comments
 (0)