Skip to content

Commit

Permalink
Merge pull request #180 from k1LoW/fix-coveage-paths
Browse files Browse the repository at this point in the history
[BREAKING] Fix building Config.Coverage.Paths
  • Loading branch information
k1LoW authored Oct 11, 2022
2 parents a06933b + ed09727 commit 27d9fcb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func (c *Config) Build() {
}
if len(c.Coverage.Paths) == 0 {
c.Coverage.Paths = append(c.Coverage.Paths, filepath.Dir(c.path))
} else {
paths := []string{}
for _, p := range c.Coverage.Paths {
paths = append(paths, filepath.Join(filepath.Dir(c.path), p))
}
c.Coverage.Paths = paths
}

// CodeToTestRatio
Expand Down
27 changes: 27 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -90,6 +91,32 @@ func TestLoadConfigCentralPush(t *testing.T) {
}
}

func TestCoveragePaths(t *testing.T) {
tests := []struct {
paths []string
configPath string
want []string
}{
{[]string{"a/b/coverage.out"}, "path/to/.octocov.yml", []string{"path/to/a/b/coverage.out"}},
{[]string{}, "path/to/.octocov.yml", []string{"path/to"}},
{[]string{"a/b/coverage.out"}, ".octocov.yml", []string{"a/b/coverage.out"}},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.paths), func(t *testing.T) {
c := New()
c.path = tt.configPath
c.Coverage = &ConfigCoverage{
Paths: tt.paths,
}
c.Build()
got := c.Coverage.Paths
if diff := cmp.Diff(got, tt.want, nil); diff != "" {
t.Errorf("%s", diff)
}
})
}
}

func TestCoverageAcceptable(t *testing.T) {
tests := []struct {
cond string
Expand Down
8 changes: 4 additions & 4 deletions testdata/octocov_parallel_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ repository: k1LoW/octocov/parallel
coverage:
acceptable: current >= 60%
paths:
- coverage_coverage.out
- coverage_ratio.out
- coverage_badge.out
- coverage_other.out
- ../coverage_coverage.out
- ../coverage_ratio.out
- ../coverage_badge.out
- ../coverage_other.out
testExecutionTime:
steps:
- Run tests pkg/coverage
Expand Down

0 comments on commit 27d9fcb

Please sign in to comment.