diff --git a/yaml/testcase.go b/yaml/testcase.go index 7f01134..ab6403c 100644 --- a/yaml/testcase.go +++ b/yaml/testcase.go @@ -1,6 +1,7 @@ package yaml import ( + "errors" "fmt" "os" "path/filepath" @@ -30,7 +31,7 @@ func ReadTestCases() ([]*TestCase, string) { panic(err) } - cases, err := collectTestCases(base, duration) + cases, err := collectTestCases(base, duration, true) if err != nil { panic(err) } @@ -38,19 +39,26 @@ func ReadTestCases() ([]*TestCase, string) { return cases, base } -func collectTestCases(base string, duration time.Duration) ([]*TestCase, error) { +func collectTestCases(base string, duration time.Duration, evaluateIgnoreFile bool) ([]*TestCase, error) { var cases []*TestCase err := filepath.WalkDir(base, func(p string, d os.DirEntry, err error) error { if err != nil { return err } - if strings.HasPrefix(p, "oats/yaml") { - // skip the test framework which might be checked out in the same directory - return nil - } if !oatsFileRegex.MatchString(d.Name()) || strings.Contains(d.Name(), "-template.yaml") { return nil } + if evaluateIgnoreFile { + if _, err := os.Stat(filepath.Join(p, ".oatsignore")); errors.Is(err, os.ErrNotExist) { + // ignore file does not exist + } else { + // ignore file exists + println("ignoring", p) + return nil + } + } + + println("adding", p) testCase, err := readTestCase(base, p, duration) if err != nil { return err diff --git a/yaml/testcase_test.go b/yaml/testcase_test.go index c5f3a97..aff7cb7 100644 --- a/yaml/testcase_test.go +++ b/yaml/testcase_test.go @@ -34,7 +34,7 @@ func TestIncludePath(t *testing.T) { } func TestCollectTestCases(t *testing.T) { - cases, err := collectTestCases("testdata", 0) + cases, err := collectTestCases("testdata", 0, false) require.NoError(t, err) require.Len(t, cases, 2) require.Equal(t, "runfoo-oats", cases[0].Name) diff --git a/yaml/testdata/.oatsignore b/yaml/testdata/.oatsignore new file mode 100644 index 0000000..e69de29