Skip to content

Commit be6fa5d

Browse files
committed
NO-JIRA: tests(buildinputs) improve project root detection, also Dockerfile.* detection (opendatahub-io#2522)
1 parent fdc238b commit be6fa5d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/buildinputs/buildinputs_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"encoding/json"
55
"os"
66
"path/filepath"
7+
"runtime"
8+
"strings"
79
"testing"
810
)
911

1012
func globDockerfiles(dir string) ([]string, error) {
1113
files := make([]string, 0)
1214
err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
13-
if filepath.Base(path) == "Dockerfile" {
15+
if strings.HasPrefix(filepath.Base(path), "Dockerfile.") {
1416
files = append(files, path)
1517
}
1618
return nil
@@ -21,8 +23,14 @@ func globDockerfiles(dir string) ([]string, error) {
2123

2224
// TestParseAllDockerfiles checks there are no panics when processing all Dockerfiles we have
2325
func TestParseAllDockerfiles(t *testing.T) {
24-
projectRoot := "../../"
26+
_, currentFilePath, _, ok := runtime.Caller(0)
27+
if !ok {
28+
t.Fatal("failed to get caller information")
29+
}
30+
31+
projectRoot := filepath.Join(filepath.Dir(currentFilePath), "../../")
2532
dockerfiles := noErr2(globDockerfiles(projectRoot))
33+
t.Logf("found %d Dockerfiles in %s", len(dockerfiles), projectRoot)
2634

2735
if len(dockerfiles) < 6 {
2836
t.Fatalf("not enough Dockerfiles found, got %+v", dockerfiles)

0 commit comments

Comments
 (0)