Skip to content

Commit 96da41c

Browse files
committed
Fix TestParseSubscriptionConfig to work with vendor mode
1 parent 12923b9 commit 96da41c

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

hack/tools/schema-generator/main_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,30 @@ import (
1212
"github.com/stretchr/testify/require"
1313
)
1414

15-
// getModulePath returns the directory path of the specified Go module from go mod cache
15+
// getModulePath returns the directory path of the specified Go module.
16+
// It first checks the vendor directory (for vendor mode builds like in OpenShift CI),
17+
// then falls back to go mod cache.
1618
func getModulePath(t *testing.T, modulePath string) string {
1719
t.Helper()
18-
// Use -mod=readonly to bypass vendor directory and get the module cache path
20+
21+
// First, check if the module exists in the vendor directory
22+
// This is needed for vendor mode builds (e.g., OpenShift CI)
23+
vendorPath := filepath.Join("vendor", modulePath)
24+
if info, err := os.Stat(vendorPath); err == nil && info.IsDir() {
25+
return vendorPath
26+
}
27+
28+
// Also check relative to the repository root (when running from subdirectory)
29+
// The test runs from hack/tools/schema-generator, so we need to go up 3 levels
30+
rootVendorPath := filepath.Join("..", "..", "..", "vendor", modulePath)
31+
if info, err := os.Stat(rootVendorPath); err == nil && info.IsDir() {
32+
return rootVendorPath
33+
}
34+
35+
// Fall back to go mod cache
1936
cmd := exec.Command("go", "list", "-mod=readonly", "-m", "-f", "{{.Dir}}", modulePath)
2037
out, err := cmd.Output()
21-
require.NoError(t, err, "failed to find module %s", modulePath)
38+
require.NoError(t, err, "failed to find module %s in vendor directory or go mod cache", modulePath)
2239
return strings.TrimSpace(string(out))
2340
}
2441

0 commit comments

Comments
 (0)