Skip to content

Commit

Permalink
ignore out own tests (#63)
Browse files Browse the repository at this point in the history
* ignore out own tests

* ignore out own tests
  • Loading branch information
zeitlinger authored Dec 16, 2024
1 parent 90517db commit 66ee5b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions yaml/testcase.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package yaml

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -30,27 +31,34 @@ func ReadTestCases() ([]*TestCase, string) {
panic(err)
}

cases, err := collectTestCases(base, duration)
cases, err := collectTestCases(base, duration, true)
if err != nil {
panic(err)
}

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
Expand Down
2 changes: 1 addition & 1 deletion yaml/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Empty file added yaml/testdata/.oatsignore
Empty file.

0 comments on commit 66ee5b1

Please sign in to comment.