Skip to content

Commit d7dc119

Browse files
authored
Add coverage reports using coveralls (#71)
#### Type of change - Test update #### Description - Add test coverage reports using coveralls #### Related issues - resolves #70 Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
1 parent 82e1878 commit d7dc119

File tree

7 files changed

+44
-57
lines changed

7 files changed

+44
-57
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ jobs:
4848
with:
4949
go-version-file: go.mod
5050
- run: scripts/install-dev-dependencies.sh
51-
- run: make test
51+
- run: make test-cover
52+
- name: Send coverage
53+
uses: shogo82148/actions-goveralls@v1
54+
with:
55+
path-to-profile: coverage.profile

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ TESTS*.xml
2525
.tox/
2626
.vagrant/
2727
.vscode
28+
*coverage.profile

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ GO_TEST_FMT_FLAGS := -hide empty-packages
5858
test: FORCE
5959
@$(go_test) ./... | gotestfmt ${GO_TEST_FMT_FLAGS}
6060

61+
# Runs test with coverage analysis.
62+
test-cover: FORCE
63+
@$(go_test) -coverprofile=coverage.profile -coverpkg=./... ./... | gotestfmt ${GO_TEST_FMT_FLAGS}
64+
@scripts/test-coverage-filter-files.sh
65+
66+
cover-report: FORCE
67+
$(go_cmd) tool cover -html=coverage.profile
68+
6169
.PHONY: $(TOOLS_EXES)
6270
## Builds a native binary
6371
$(TOOLS_EXES): %: $(BUILD_DIR)/%

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ SPDX-License-Identifier: Apache-2.0
55
-->
66
# Fabric-X Common
77

8+
[![Coverage Status](https://coveralls.io/repos/github/hyperledger/fabric-x-common/badge.svg?branch=main)](https://coveralls.io/github/hyperledger/fabric-x-common?branch=main)
9+
810
This library encapsulates some common code across Fabric-X ecosystem.
911
This code have been taken from [Hyperledger Fabric](https://github.com/hyperledger/fabric) v3.0.0-rc1.
1012

common/deliverclient/orderers/connection.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ type OrdererOrg struct {
5757
RootCerts [][]byte
5858
}
5959

60+
func (o *OrdererOrg) String() string {
61+
return fmt.Sprintf("Addresses: %v", o.Addresses)
62+
}
63+
6064
func NewConnectionSource(logger *flogging.FabricLogger, overrides map[string]*Endpoint, selfEndpoint string) *ConnectionSource {
6165
return &ConnectionSource{
6266
orgToEndpointsHash: map[string][]byte{},

common/errors/errors.go

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
# We filter some of the files for test coverage reporting.
9+
sed -i -E -f - coverage.profile <<EOF
10+
# The main file cannot be covered by tests as it may call os.Exit(1).
11+
/main\.go/d
12+
# Generated files (e.g., mocks, protobuf) may contain unused methods.
13+
/\.pb(\.gw)?\.go/d
14+
/\/mocks?\//d
15+
/\/fakes?\//d
16+
# Test files that are included in non-test files.
17+
/test_exports?\.go/d
18+
/\/test\//d
19+
/configtest\//d
20+
/testtools\//d
21+
/testprotos\//d
22+
/testutil\//d
23+
/configtest\//d
24+
EOF

0 commit comments

Comments
 (0)