From 254105c5fbe3165a5207c89a759400b369fc620e Mon Sep 17 00:00:00 2001 From: Vlado Date: Sun, 2 Apr 2023 14:52:45 +0100 Subject: [PATCH] zero config defaults --- .testcoverage.example.yml | 2 +- README.md | 2 +- main.go | 4 ++-- pkg/testcoverage/config.go | 16 ---------------- pkg/testcoverage/config_test.go | 20 +++----------------- pkg/testcoverage/export_test.go | 11 ++++------- 6 files changed, 11 insertions(+), 44 deletions(-) diff --git a/.testcoverage.example.yml b/.testcoverage.example.yml index fab91724..1e5269fc 100644 --- a/.testcoverage.example.yml +++ b/.testcoverage.example.yml @@ -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 diff --git a/README.md b/README.md index 0aa5a5fa..4511e20d 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/main.go b/main.go index 6eee4eda..9ece249f 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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, diff --git a/pkg/testcoverage/config.go b/pkg/testcoverage/config.go index 39978670..8e8e4c28 100644 --- a/pkg/testcoverage/config.go +++ b/pkg/testcoverage/config.go @@ -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"` @@ -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 } diff --git a/pkg/testcoverage/config_test.go b/pkg/testcoverage/config_test.go index fe0c6521..abb78753 100644 --- a/pkg/testcoverage/config_test.go +++ b/pkg/testcoverage/config_test.go @@ -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 @@ -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) } diff --git a/pkg/testcoverage/export_test.go b/pkg/testcoverage/export_test.go index 527b5833..0385fa69 100644 --- a/pkg/testcoverage/export_test.go +++ b/pkg/testcoverage/export_test.go @@ -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 (