Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .testcoverage.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ threshold:
# The minimum coverage that each package should have
package: 80

# (optional; default 50)
# (optional; default 0)
# The minimum total coverage project should have
total: 95
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ threshold:
# The minimum coverage that each package should have
package: 80

# (optional; default 50)
# (optional; default 0)
# The minimum total coverage project should have
total: 95
```
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (args) Version() string {
}

func (a *args) toConfig() testcoverage.Config {
cfg := testcoverage.NewConfig()
cfg := testcoverage.Config{}

cfg.Profile = fromMagicToEmpty(a.Profile)
cfg.GithubActionOutput = a.GithubActionOutput
Expand All @@ -65,7 +65,7 @@ func main() {
}

func readConfig() (testcoverage.Config, error) {
cfg := testcoverage.NewConfig()
cfg := testcoverage.Config{}
cmdArgs := args{
GithubActionOutput: cfg.GithubActionOutput,
ThresholdFile: cfg.Threshold.File,
Expand Down
16 changes: 0 additions & 16 deletions pkg/testcoverage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ var (
ErrCoverageProfileNotSpecified = fmt.Errorf("coverage profile file not specified")
)

const (
defaultFileThreshold = 0
defaultPackageThreshold = 0
defaultTotalThreshold = 50
)

type Config struct {
Profile string `yaml:"profile"`
LocalPrefix string `yaml:"local-prefix"`
Expand All @@ -31,16 +25,6 @@ type Threshold struct {
Total int `yaml:"total"`
}

func NewConfig() Config {
return Config{
Threshold: Threshold{
File: defaultFileThreshold,
Package: defaultPackageThreshold,
Total: defaultTotalThreshold,
},
}
}

func (c Config) Validate() error {
inRange := func(t int) bool { return t >= 0 && t <= 100 }

Expand Down
20 changes: 3 additions & 17 deletions pkg/testcoverage/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ import (
. "github.com/vladopajic/go-test-coverage/pkg/testcoverage"
)

func Test_NewConfig(t *testing.T) {
t.Parallel()

cfg := NewConfig()

assert.Empty(t, cfg.Profile)
assert.Empty(t, cfg.LocalPrefix)
assert.False(t, cfg.GithubActionOutput)
assert.Equal(t, DefaultFileThreshold, cfg.Threshold.File)
assert.Equal(t, DefaultPackageThreshold, cfg.Threshold.Package)
assert.Equal(t, DefaultTotalThreshold, cfg.Threshold.Total)
}

func Test_Config_Validate(t *testing.T) {
t.Parallel()

newValidCfg := func() Config {
cfg := NewConfig()
cfg := Config{}
cfg.Profile = "cover.out"

return cfg
Expand Down Expand Up @@ -66,9 +53,8 @@ func Test_Config_Validate(t *testing.T) {
func Test_ConfigFromFile(t *testing.T) {
t.Parallel()

cfg := NewConfig()
cfgBefore := NewConfig()
cfg := Config{}
err := ConfigFromFile(&cfg, t.TempDir())
assert.Error(t, err)
assert.Equal(t, cfgBefore, cfg)
assert.Equal(t, Config{}, cfg)
}
11 changes: 4 additions & 7 deletions pkg/testcoverage/export_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package testcoverage

const (
DefaultFileThreshold = defaultFileThreshold
DefaultPackageThreshold = defaultPackageThreshold
DefaultTotalThreshold = defaultTotalThreshold
GaOutputFileEnv = gaOutputFileEnv
GaOutputTotalCoverage = gaOutputTotalCoverage
GaOutputBadgeColor = gaOutputBadgeColor
GaOutputBadgeText = gaOutputBadgeText
GaOutputFileEnv = gaOutputFileEnv
GaOutputTotalCoverage = gaOutputTotalCoverage
GaOutputBadgeColor = gaOutputBadgeColor
GaOutputBadgeText = gaOutputBadgeText
)

var (
Expand Down