Skip to content

Commit 3a1bbc3

Browse files
Merge pull request #64 from macadmins/coverage
Better coverage test
2 parents 7c876dd + 8a2e5a6 commit 3a1bbc3

File tree

4 files changed

+100
-27
lines changed

4 files changed

+100
-27
lines changed

.github/workflows/coverage.yml

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
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@v4
159
with:
1610
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
11+
- name: generate test coverage
12+
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
13+
- name: check test coverage
14+
uses: vladopajic/go-test-coverage@v2
2515
with:
26-
coverage-files: coverage/lcov.info
27-
minimum-coverage: 40
28-
github-token: ${{ secrets.GITHUB_TOKEN }}
29-
update-comment: true
16+
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

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
- path: ^tables/mdm$
46+
threshold: 38
47+
- path: tables/mdm/mdm.go
48+
threshold: 38
49+
# Holds regexp rules which will exclude matched files or packages
50+
# from coverage statistics.
51+
exclude:
52+
# Exclude files or packages matching their paths
53+
paths:
54+
- main.go
55+
- pkg/utils/exec.go
56+
- tables/fileline/file_line.go
57+
- tables/unifiedlog/unified_log.go
58+
- ^tables/networkquality$
59+
- ^tables/unifiedlog$
60+
- ^tables/puppet$
61+
- ^tables/unifiedlog$
62+
- ^tables/pendingappleupdates$
63+
- ^tables/fileline$
64+
- tables/unifiedlog/unified_log.go
65+
- tables/networkquality/networkquality.go
66+
- tables/pendingappleupdates/pendingappleupdates.go
67+
- tables/puppet/puppet_facts.go
68+
- tables/puppet/puppet_info.go
69+
- tables/puppet/puppet_logs.go
70+
- tables/puppet/puppet_state.go
71+
- tables/puppet/yaml.go
72+
# - \.pb\.go$ # excludes all protobuf generated files
73+
# - ^pkg/bar # exclude package `pkg/bar`
74+
75+
# File name of go-test-coverage breakdown file, which can be used to
76+
# analyze coverage difference.
77+
breakdown-file-name: ""
78+
79+
diff:
80+
# File name of go-test-coverage breakdown file which will be used to
81+
# report coverage difference.
82+
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)