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
1 change: 0 additions & 1 deletion .github/.testcoverage-local.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Config file for go-test-coverage running locally.

profile: cover.profile
local-prefix: github.com/vladopajic/go-test-coverage/v2
threshold:
file: 100
total: 98
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/action-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
id: test-3
with:
profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold-file: 0
threshold-package: 0
threshold-total: 0
Expand All @@ -108,7 +107,6 @@ jobs:
continue-on-error: true
with:
profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold-file: 0
threshold-package: 0
threshold-total: 100
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/testdata/total100.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file is used for integration tests

profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold:
file: 0
package: 0
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/testdata/zero.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This file is used for integration tests

profile: cover.out
local-prefix: "github.com/vladopajic/go-test-coverage/v2"
threshold:
file: 0
package: 0
Expand Down
4 changes: 0 additions & 4 deletions .testcoverage.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
profile: cover.out

# (optional; but recommended to set)
# When specified reported file paths will not contain local prefix in the output.
local-prefix: "github.com/org/project"

# Holds coverage thresholds percentages, values should be in range [0-100].
threshold:
# (optional; default 0)
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ Here’s an example [.testcoverage.yml](./.testcoverage.example.yml) configurati
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
profile: cover.out

# (optional; but recommended to set)
# When specified reported file paths will not contain local prefix in the output.
local-prefix: "github.com/org/project"

# Holds coverage thresholds percentages, values should be in range [0-100].
threshold:
# (optional; default 0)
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ inputs:
required: false
default: ""
type: string
local-prefix:
description: When specified reported file paths will not contain local prefix in the output. Overrides value from configuration.
# DEPRECATED
local-prefix:
description: DEPRECATED! not used anymore.
required: false
default: ""
type: string
Expand Down Expand Up @@ -132,7 +133,6 @@ runs:
- --config=${{ inputs.config || '''''' }}
- --profile=${{ inputs.profile || '''''' }}
- --github-action-output=true
- --local-prefix=${{ inputs.local-prefix || '''''' }}
- --threshold-file=${{ inputs.threshold-file }}
- --threshold-package=${{ inputs.threshold-package }}
- --threshold-total=${{ inputs.threshold-total }}
Expand Down
4 changes: 0 additions & 4 deletions docs/badge.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Example:
uses: vladopajic/go-test-coverage@v2
with:
profile: cover.out
local-prefix: github.com/org/project
threshold-total: 95

## when token is not specified (value '') this feature is turned off
Expand Down Expand Up @@ -67,7 +66,6 @@ Example:
uses: vladopajic/go-test-coverage@v2
with:
profile: cover.out
local-prefix: github.com/org/project
threshold-total: 95

## when secret is not specified (value '') this feature is turned off.
Expand All @@ -94,7 +92,6 @@ Example:
uses: vladopajic/go-test-coverage@v2
with:
profile: cover.out
local-prefix: github.com/org/project
threshold-total: 95

# badge will be generated and store on file system with `coverage.svg` name
Expand All @@ -113,7 +110,6 @@ Example:
uses: vladopajic/go-test-coverage@v2
with:
profile: cover.out
local-prefix: github.com/org/project
threshold-total: 95

## in this case token should be from other repository that will host badges.
Expand Down
1 change: 0 additions & 1 deletion docs/github_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Alternatively, if you don't need advanced configuration options from a config fi
uses: vladopajic/go-test-coverage@v2
with:
profile: cover.out
local-prefix: github.com/org/project
threshold-file: 80
threshold-package: 80
threshold-total: 95
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
type args struct {
ConfigPath string `arg:"-c,--config"`
Profile string `arg:"-p,--profile" help:"path to coverage profile"`
LocalPrefix string `arg:"-l,--local-prefix"`
LocalPrefix string `arg:"-l,--local-prefix"` // deprecated
GithubActionOutput bool `arg:"-o,--github-action-output"`
ThresholdFile int `arg:"-f,--threshold-file"`
ThresholdPackage int `arg:"-k,--threshold-package"`
Expand Down Expand Up @@ -99,7 +99,7 @@ func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, err
}

if !isCIDefaultString(a.LocalPrefix) {
cfg.LocalPrefix = a.LocalPrefix
cfg.LocalPrefixDeprecated = a.LocalPrefix
}

if !isCIDefaultInt(a.ThresholdFile) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/testcoverage/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func Check(w io.Writer, cfg Config) bool {
fmt.Fprintf(w, "failed setting github action output: %v\n", err)
return false
}

if cfg.LocalPrefixDeprecated != "" { // coverage-ignore
reportGHWarning(w, "Deprecated option",
"local-prefix option is deprecated since v2.13.0, you can safely remove setting this option")
}
}

err = generateAndSaveBadge(w, cfg, result.TotalStats.CoveredPercentage())
Expand All @@ -68,8 +73,8 @@ func reportForHuman(w io.Writer, result AnalyzeResult) string {
func GenerateCoverageStats(cfg Config) ([]coverage.Stats, error) {
return coverage.GenerateCoverageStats(coverage.Config{ //nolint:wrapcheck // err wrapped above
Profiles: strings.Split(cfg.Profile, ","),
LocalPrefix: cfg.LocalPrefix,
ExcludePaths: cfg.Exclude.Paths,
RootDir: cfg.RootDir,
})
}

Expand Down
60 changes: 36 additions & 24 deletions pkg/testcoverage/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
profileNOK = testdataDir + testdata.ProfileNOK
breakdownOK = testdataDir + testdata.BreakdownOK
breakdownNOK = testdataDir + testdata.BreakdownNOK

prefix = "github.com/vladopajic/go-test-coverage/v2"
rootDir = "../../"
)

func TestCheck(t *testing.T) {
Expand All @@ -30,8 +33,6 @@ func TestCheck(t *testing.T) {
return
}

const prefix = "github.com/vladopajic/go-test-coverage/v2"

t.Run("no profile", func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -59,11 +60,12 @@ func TestCheck(t *testing.T) {
t.Parallel()

buf := &bytes.Buffer{}
cfg := Config{Profile: profileOK, Threshold: Threshold{Total: 65}}
cfg := Config{Profile: profileOK, Threshold: Threshold{Total: 65}, RootDir: rootDir}
pass := Check(buf, cfg)
assert.True(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
assertHumanReport(t, buf.String(), 1, 0)
assertNoFileNames(t, buf.String(), prefix)
assertNoUncoveredLinesInfo(t, buf.String())
})

Expand All @@ -77,6 +79,7 @@ func TestCheck(t *testing.T) {
Exclude: Exclude{
Paths: []string{`cdn\.go$`, `github\.go$`, `cover\.go$`, `check\.go$`, `path\.go$`},
},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.True(t, pass)
Expand All @@ -89,7 +92,7 @@ func TestCheck(t *testing.T) {
t.Parallel()

buf := &bytes.Buffer{}
cfg := Config{Profile: profileOK, Threshold: Threshold{Total: 100}}
cfg := Config{Profile: profileOK, Threshold: Threshold{Total: 100}, RootDir: rootDir}
pass := Check(buf, cfg)
assert.False(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
Expand All @@ -102,20 +105,6 @@ func TestCheck(t *testing.T) {
})
})

t.Run("valid profile - pass with prefix", func(t *testing.T) {
t.Parallel()

buf := &bytes.Buffer{}

cfg := Config{Profile: profileOK, LocalPrefix: prefix, Threshold: Threshold{Total: 65}}
pass := Check(buf, cfg)
assert.True(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
assertHumanReport(t, buf.String(), 1, 0)
assertNoFileNames(t, buf.String(), prefix)
assertNoUncoveredLinesInfo(t, buf.String())
})

t.Run("valid profile - pass after override", func(t *testing.T) {
t.Parallel()

Expand All @@ -124,6 +113,7 @@ func TestCheck(t *testing.T) {
Profile: profileOK,
Threshold: Threshold{File: 100},
Override: []Override{{Threshold: 10, Path: "^pkg"}},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.True(t, pass)
Expand All @@ -141,6 +131,7 @@ func TestCheck(t *testing.T) {
Profile: profileOK,
Threshold: Threshold{File: 10},
Override: []Override{{Threshold: 100, Path: "^pkg"}},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
Expand All @@ -162,6 +153,7 @@ func TestCheck(t *testing.T) {
Profile: profileOK,
Threshold: Threshold{File: 70},
Override: []Override{{Threshold: 60, Path: "pkg/testcoverage/badgestorer/github.go"}},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.True(t, pass)
Expand All @@ -179,6 +171,7 @@ func TestCheck(t *testing.T) {
Profile: profileOK,
Threshold: Threshold{File: 70},
Override: []Override{{Threshold: 80, Path: "pkg/testcoverage/badgestorer/github.go"}},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
Expand All @@ -202,6 +195,7 @@ func TestCheck(t *testing.T) {
Badge: Badge{
FileName: t.TempDir(), // should failed because this is dir
},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
Expand All @@ -215,6 +209,7 @@ func TestCheck(t *testing.T) {
cfg := Config{
Profile: profileOK,
BreakdownFileName: t.TempDir(), // should failed because this is dir
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
Expand All @@ -228,6 +223,7 @@ func TestCheck(t *testing.T) {
cfg := Config{
Profile: profileOK,
BreakdownFileName: t.TempDir() + "/breakdown.testcoverage",
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.True(t, pass)
Expand All @@ -250,6 +246,7 @@ func TestCheck(t *testing.T) {
Diff: Diff{
BaseBreakdownFileName: t.TempDir(), // should failed because this is dir
},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
Expand All @@ -267,7 +264,12 @@ func TestCheckNoParallel(t *testing.T) {
t.Setenv(GaOutputFileEnv, "")

buf := &bytes.Buffer{}
cfg := Config{Profile: profileOK, GithubActionOutput: true, Threshold: Threshold{Total: 100}}
cfg := Config{
Profile: profileOK,
GithubActionOutput: true,
Threshold: Threshold{Total: 100},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
})
Expand All @@ -277,7 +279,12 @@ func TestCheckNoParallel(t *testing.T) {
t.Setenv(GaOutputFileEnv, testFile)

buf := &bytes.Buffer{}
cfg := Config{Profile: profileOK, GithubActionOutput: true, Threshold: Threshold{Total: 10}}
cfg := Config{
Profile: profileOK,
GithubActionOutput: true,
Threshold: Threshold{Total: 10},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.True(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 0)
Expand All @@ -291,7 +298,12 @@ func TestCheckNoParallel(t *testing.T) {
t.Setenv(GaOutputFileEnv, testFile)

buf := &bytes.Buffer{}
cfg := Config{Profile: profileOK, GithubActionOutput: true, Threshold: Threshold{Total: 100}}
cfg := Config{
Profile: profileOK,
GithubActionOutput: true,
Threshold: Threshold{Total: 100},
RootDir: rootDir,
}
pass := Check(buf, cfg)
assert.False(t, pass)
assertGithubActionErrorsCount(t, buf.String(), 1)
Expand Down Expand Up @@ -319,7 +331,7 @@ func Test_Analyze(t *testing.T) {
t.Parallel()

result := Analyze(
Config{LocalPrefix: prefix, Threshold: Threshold{Total: 10}},
Config{Threshold: Threshold{Total: 10}},
randStats(prefix, 10, 100),
nil,
)
Expand Down Expand Up @@ -350,7 +362,7 @@ func Test_Analyze(t *testing.T) {
t.Parallel()

result := Analyze(
Config{LocalPrefix: prefix, Threshold: Threshold{File: 10}},
Config{Threshold: Threshold{File: 10}},
randStats(prefix, 10, 100),
nil,
)
Expand Down Expand Up @@ -379,7 +391,7 @@ func Test_Analyze(t *testing.T) {
t.Parallel()

result := Analyze(
Config{LocalPrefix: prefix, Threshold: Threshold{Package: 10}},
Config{Threshold: Threshold{Package: 10}},
randStats(prefix, 10, 100),
nil,
)
Expand Down
19 changes: 10 additions & 9 deletions pkg/testcoverage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ var (
)

type Config struct {
Profile string `yaml:"profile"`
LocalPrefix string `yaml:"local-prefix"`
Threshold Threshold `yaml:"threshold"`
Override []Override `yaml:"override,omitempty"`
Exclude Exclude `yaml:"exclude"`
BreakdownFileName string `yaml:"breakdown-file-name"`
GithubActionOutput bool `yaml:"github-action-output"`
Diff Diff `yaml:"diff"`
Badge Badge `yaml:"-"`
Profile string `yaml:"profile"`
LocalPrefixDeprecated string `yaml:"-"`
Threshold Threshold `yaml:"threshold"`
Override []Override `yaml:"override,omitempty"`
Exclude Exclude `yaml:"exclude"`
BreakdownFileName string `yaml:"breakdown-file-name"`
GithubActionOutput bool `yaml:"github-action-output"`
Diff Diff `yaml:"diff"`
Badge Badge `yaml:"-"`
RootDir string `yaml:"-"`
}

type Threshold struct {
Expand Down
Loading
Loading