@@ -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.
1618func 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