Skip to content

Commit 7f2a120

Browse files
committed
add test converage configuration
1 parent acd06ba commit 7f2a120

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed

.github/workflows/go.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will build a golang project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
33

4-
name: Go
4+
name: Go CI Worflow with test coverage check
55

66
on:
77
push:
@@ -19,10 +19,26 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v4
2121
with:
22-
go-version: '1.20'
22+
go-version: '1.21'
2323

24-
- name: Build
25-
run: go build -v ./...
2624

27-
- name: Test
28-
run: go test -v ./...
25+
- name: generate test coverage
26+
run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
27+
28+
- name: check test coverage
29+
uses: vladopajic/go-test-coverage@v2
30+
with:
31+
# Configure action using config file (option 1)
32+
config: ./.testcoverage.yml
33+
34+
# Configure action by specifying input parameters individually (option 2).
35+
# If you are using config file (option 1) you shouldn't use these parameters, however
36+
# specifing these action parameters will override appropriate config values.
37+
profile: cover.out
38+
local-prefix: github.com/org/project
39+
threshold-file: 70
40+
threshold-package: 70
41+
threshold-total: 70
42+
43+
- name: Build
44+
run: go build -v ./...

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea/
1+
.idea/
2+
cover.out

.testcoverage.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# (mandatory)
2+
# Path to coverprofile 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/org/project"
13+
14+
# Holds coverage thresholds percentages, values should be in range [0-100]
15+
threshold:
16+
# (optional; default 0)
17+
# The minimum coverage that each file should have
18+
file: 65
19+
20+
# (optional; default 0)
21+
# The minimum coverage that each package should have
22+
package: 65
23+
24+
# (optional; default 0)
25+
# The minimum total coverage project should have
26+
total: 65
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+
# Increase coverage threshold to 100% for `foo` package
36+
# (default is 80, as configured above in this example)
37+
- threshold: 65
38+
path: .
39+
# path: ^pkg/lib/foo$
40+
41+
# Holds regexp rules which will exclude matched files or packages
42+
# from coverage statistics
43+
exclude:
44+
# Exclude files or packages matching their paths
45+
paths:
46+
- \.pb\.go$ # excludes all protobuf generated files
47+
- ^pkg/bar # exclude package `pkg/bar`
48+
49+
# NOTES:
50+
# - symbol `/` in all path regexps will be replaced by current OS file path separator
51+
# to properly work on Windows

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include .env.example
2+
#export
3+
4+
LOCAL_BIN:=$(CURDIR)/bin
5+
PATH:=$(LOCAL_BIN):$(PATH)
6+
GOBIN ?= $$(go env GOPATH)/bin
7+
8+
.PHONY: install-go-test-coverage
9+
install-go-test-coverage:
10+
go install github.com/vladopajic/go-test-coverage/v2@latest
11+
12+
.PHONY: check-coverage
13+
check-coverage: install-go-test-coverage
14+
go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
15+
${GOBIN}/go-test-coverage --config=./.testcoverage.yml
16+
17+
18+
.PHONY: format
19+
format:
20+
gofmt -l -w .

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# GO-Lib: Configurations
1+
# Go Configurations
22

33
## How to Use
44

55
- Read Configuration from file
6+
- Configuration to Struct
7+
- Configuration to Struct by Key:nested configuration
68

79
```shell
810
appconfig, _ := NewYamlConfig("config.yaml")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/fluent-qa/qfluentconf
22

3-
go 1.21.4
3+
go 1.22.6
44

55
require (
66
github.com/fsnotify/fsnotify v1.7.0

0 commit comments

Comments
 (0)