Skip to content

Commit 0a145a8

Browse files
committed
Better coverage test
1 parent 7c876dd commit 0a145a8

File tree

4 files changed

+97
-29
lines changed

4 files changed

+97
-29
lines changed

.github/workflows/coverage.yml

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
name: Test Coverage
2-
32
on: [pull_request]
4-
53
jobs:
64
coverage:
7-
85
runs-on: ubuntu-latest
9-
permissions: write-all
106
steps:
117
- uses: actions/checkout@v3
12-
13-
- name: Set up Go
14-
uses: actions/setup-go@v4
8+
- uses: actions/setup-go@v3
9+
- name: generate test coverage
10+
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
11+
- name: check test coverage
12+
uses: vladopajic/go-test-coverage@v2
1513
with:
16-
go-version: ${{ env.GO_VERSION }}
17-
18-
- name: Test Coverage
19-
run: make coverage
20-
21-
- name: Setup LCOV
22-
uses: hrishikesh-kadam/setup-lcov@d100c36c45e4f64950fb746cd28713f6c756a9c1
23-
- name: Report code coverage
24-
uses: zgosalvez/github-actions-report-lcov@5f5c6e77851c41ab9c69a212690c1040bb916016
25-
with:
26-
coverage-files: coverage/lcov.info
27-
minimum-coverage: 40
28-
github-token: ${{ secrets.GITHUB_TOKEN }}
29-
update-comment: true
14+
config: ./.testcoverage.yml

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ macadmins_extension
55
config.mk
66
bazel-*
77
coverage/*
8-
version_config.go
8+
version_config.go
9+
cover.out

.testcoverage.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# (mandatory)
2+
# Path to coverage profile file (output of `go test -coverprofile` command).
3+
#
4+
# For cases where there are many coverage profiles, such as when running
5+
# unit tests and integration tests separately, you can combine all those
6+
# profiles into one. In this case, the profile should have a comma-separated list
7+
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
8+
profile: cover.out
9+
10+
# (optional; but recommended to set)
11+
# When specified reported file paths will not contain local prefix in the output.
12+
local-prefix: "github.com/macadmins/osquery-extension"
13+
14+
# Holds coverage thresholds percentages, values should be in range [0-100].
15+
threshold:
16+
# (optional; default 0)
17+
# Minimum coverage percentage required for individual files.
18+
file: 40
19+
20+
# (optional; default 0)
21+
# Minimum coverage percentage required for each package.
22+
package: 40
23+
24+
# (optional; default 0)
25+
# Minimum overall project coverage percentage required.
26+
total: 40
27+
28+
# Holds regexp rules which will override thresholds for matched files or packages
29+
# using their paths.
30+
#
31+
# First rule from this list that matches file or package is going to apply
32+
# new threshold to it. If project has multiple rules that match same path,
33+
# override rules should be listed in order from specific to more general rules.
34+
override:
35+
- path: tables/filevaultusers/filevaultusers.go
36+
threshold: 36
37+
- path: tables/macos_profiles/macos_profiles.go
38+
threshold: 36
39+
- path: tables/sofa/sofa_cves.go
40+
threshold: 26
41+
- path: ^tables/macos_profiles$
42+
threshold: 36
43+
- path: ^tables/filevaultusers$
44+
threshold: 36
45+
46+
# Holds regexp rules which will exclude matched files or packages
47+
# from coverage statistics.
48+
exclude:
49+
# Exclude files or packages matching their paths
50+
paths:
51+
- main.go
52+
- pkg/utils/exec.go
53+
- tables/fileline/file_line.go
54+
- tables/unifiedlog/unified_log.go
55+
- ^tables/networkquality$
56+
- ^tables/unifiedlog$
57+
- ^tables/puppet$
58+
- ^tables/unifiedlog$
59+
- ^tables/pendingappleupdates$
60+
- ^tables/fileline$
61+
- tables/unifiedlog/unified_log.go
62+
- tables/networkquality/networkquality.go
63+
- tables/pendingappleupdates/pendingappleupdates.go
64+
- tables/puppet/puppet_facts.go
65+
- tables/puppet/puppet_info.go
66+
- tables/puppet/puppet_logs.go
67+
- tables/puppet/puppet_state.go
68+
- tables/puppet/yaml.go
69+
# - \.pb\.go$ # excludes all protobuf generated files
70+
# - ^pkg/bar # exclude package `pkg/bar`
71+
72+
# File name of go-test-coverage breakdown file, which can be used to
73+
# analyze coverage difference.
74+
breakdown-file-name: ""
75+
76+
diff:
77+
# File name of go-test-coverage breakdown file which will be used to
78+
# report coverage difference.
79+
base-breakdown-file-name: ""

Makefile

+10-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ PKGDIR_TMP = ${TMPDIR}golang
1111

1212
all: build
1313

14-
.PHONY: clean .pre-build deps init gazelle update-repos test coverage build osqueryi zip
14+
.PHONY: clean .pre-build deps init gazelle update-repos test coverage build osqueryi zip install-go-test-coverage
15+
16+
GOBIN ?= $$(go env GOPATH)/bin
17+
18+
install-go-test-coverage:
19+
go install github.com/vladopajic/go-test-coverage/v2@latest
20+
21+
coverage: install-go-test-coverage
22+
go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
23+
${GOBIN}/go-test-coverage --config=./.testcoverage.yml
1524

1625
.pre-build: clean
1726
mkdir -p build/darwin
@@ -43,12 +52,6 @@ update-repos:
4352
test:
4453
bazel test --test_output=errors //...
4554

46-
coverage:
47-
rm -rf coverage
48-
mkdir -p coverage
49-
bazel coverage --combined_report=lcov //...
50-
mv $(BAZEL_OUTPUT_PATH)/_coverage/_coverage_report.dat coverage/lcov.info
51-
5255
build: .pre-build
5356
bazel build --verbose_failures //:osquery-extension-mac-amd
5457
bazel build --verbose_failures //:osquery-extension-mac-arm

0 commit comments

Comments
 (0)