Skip to content

Commit

Permalink
Auto-skip failing test when executed in bad GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Jan 19, 2024
1 parent 7b61cf6 commit 079f581
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ import (
"os/exec"
"path"
"path/filepath"
"reflect"
"strings"
"testing"
)

func TestGenerate(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
currPkg := reflect.TypeOf(empty{}).PkgPath()
if !strings.HasPrefix(currPkg, "k8s.io/code-generator") {
t.Skipf("skipping test in vendored package %s", currPkg)
}

_ = klogtest.InitKlog(t)
klog.SetLogger(ktesting.NewLogger(t, ktesting.NewConfig()))
Expand Down Expand Up @@ -73,6 +79,11 @@ func prepareWorkdir(tb testing.TB) (string, string) {
} else {
sourcedir = path.Join(root, "examples")
}
if rd, err := filepath.EvalSymlinks(sourcedir); err != nil {
tb.Fatal(err)
} else {
sourcedir = rd
}
if _, err := os.Stat(sourcedir); err != nil {
tb.Fatal(err)
}
Expand Down Expand Up @@ -129,3 +140,5 @@ func hashdir(dir string) (string, error) {
// as hex encoded string
return hex.EncodeToString(hash.Sum(nil)), nil
}

type empty struct{}

0 comments on commit 079f581

Please sign in to comment.