Skip to content

Commit e5a52ef

Browse files
authored
zero config default values (#8)
1 parent 3bf20be commit e5a52ef

File tree

6 files changed

+11
-44
lines changed

6 files changed

+11
-44
lines changed

.testcoverage.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ threshold:
2020
# The minimum coverage that each package should have
2121
package: 80
2222

23-
# (optional; default 50)
23+
# (optional; default 0)
2424
# The minimum total coverage project should have
2525
total: 95

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ threshold:
6363
# The minimum coverage that each package should have
6464
package: 80
6565

66-
# (optional; default 50)
66+
# (optional; default 0)
6767
# The minimum total coverage project should have
6868
total: 95
6969
```

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (args) Version() string {
3838
}
3939

4040
func (a *args) toConfig() testcoverage.Config {
41-
cfg := testcoverage.NewConfig()
41+
cfg := testcoverage.Config{}
4242

4343
cfg.Profile = fromMagicToEmpty(a.Profile)
4444
cfg.GithubActionOutput = a.GithubActionOutput
@@ -65,7 +65,7 @@ func main() {
6565
}
6666

6767
func readConfig() (testcoverage.Config, error) {
68-
cfg := testcoverage.NewConfig()
68+
cfg := testcoverage.Config{}
6969
cmdArgs := args{
7070
GithubActionOutput: cfg.GithubActionOutput,
7171
ThresholdFile: cfg.Threshold.File,

pkg/testcoverage/config.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ var (
1212
ErrCoverageProfileNotSpecified = fmt.Errorf("coverage profile file not specified")
1313
)
1414

15-
const (
16-
defaultFileThreshold = 0
17-
defaultPackageThreshold = 0
18-
defaultTotalThreshold = 50
19-
)
20-
2115
type Config struct {
2216
Profile string `yaml:"profile"`
2317
LocalPrefix string `yaml:"local-prefix"`
@@ -31,16 +25,6 @@ type Threshold struct {
3125
Total int `yaml:"total"`
3226
}
3327

34-
func NewConfig() Config {
35-
return Config{
36-
Threshold: Threshold{
37-
File: defaultFileThreshold,
38-
Package: defaultPackageThreshold,
39-
Total: defaultTotalThreshold,
40-
},
41-
}
42-
}
43-
4428
func (c Config) Validate() error {
4529
inRange := func(t int) bool { return t >= 0 && t <= 100 }
4630

pkg/testcoverage/config_test.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,11 @@ import (
88
. "github.com/vladopajic/go-test-coverage/pkg/testcoverage"
99
)
1010

11-
func Test_NewConfig(t *testing.T) {
12-
t.Parallel()
13-
14-
cfg := NewConfig()
15-
16-
assert.Empty(t, cfg.Profile)
17-
assert.Empty(t, cfg.LocalPrefix)
18-
assert.False(t, cfg.GithubActionOutput)
19-
assert.Equal(t, DefaultFileThreshold, cfg.Threshold.File)
20-
assert.Equal(t, DefaultPackageThreshold, cfg.Threshold.Package)
21-
assert.Equal(t, DefaultTotalThreshold, cfg.Threshold.Total)
22-
}
23-
2411
func Test_Config_Validate(t *testing.T) {
2512
t.Parallel()
2613

2714
newValidCfg := func() Config {
28-
cfg := NewConfig()
15+
cfg := Config{}
2916
cfg.Profile = "cover.out"
3017

3118
return cfg
@@ -66,9 +53,8 @@ func Test_Config_Validate(t *testing.T) {
6653
func Test_ConfigFromFile(t *testing.T) {
6754
t.Parallel()
6855

69-
cfg := NewConfig()
70-
cfgBefore := NewConfig()
56+
cfg := Config{}
7157
err := ConfigFromFile(&cfg, t.TempDir())
7258
assert.Error(t, err)
73-
assert.Equal(t, cfgBefore, cfg)
59+
assert.Equal(t, Config{}, cfg)
7460
}

pkg/testcoverage/export_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package testcoverage
22

33
const (
4-
DefaultFileThreshold = defaultFileThreshold
5-
DefaultPackageThreshold = defaultPackageThreshold
6-
DefaultTotalThreshold = defaultTotalThreshold
7-
GaOutputFileEnv = gaOutputFileEnv
8-
GaOutputTotalCoverage = gaOutputTotalCoverage
9-
GaOutputBadgeColor = gaOutputBadgeColor
10-
GaOutputBadgeText = gaOutputBadgeText
4+
GaOutputFileEnv = gaOutputFileEnv
5+
GaOutputTotalCoverage = gaOutputTotalCoverage
6+
GaOutputBadgeColor = gaOutputBadgeColor
7+
GaOutputBadgeText = gaOutputBadgeText
118
)
129

1310
var (

0 commit comments

Comments
 (0)