diff --git a/config/build.go b/config/build.go index bfd63117..5579e6d5 100644 --- a/config/build.go +++ b/config/build.go @@ -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 diff --git a/config/config_test.go b/config/config_test.go index 43eb1a67..740731c0 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "os" "path/filepath" "strings" @@ -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 diff --git a/testdata/octocov_parallel_tests.yml b/testdata/octocov_parallel_tests.yml index 61c00b44..02a1f1fe 100644 --- a/testdata/octocov_parallel_tests.yml +++ b/testdata/octocov_parallel_tests.yml @@ -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