Skip to content

Commit 46f9978

Browse files
authored
Fix TestParseSubscriptionConfig to work with vendor mode (#2466)
1 parent 12923b9 commit 46f9978

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

hack/tools/schema-generator/main_test.go

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

15-
// getModulePath returns the directory path of the specified Go module from go mod cache
16-
func getModulePath(t *testing.T, modulePath string) string {
15+
// getPackageDir returns the directory path of the specified Go package.
16+
// It uses 'go list' which automatically handles both vendor mode and module cache.
17+
func getPackageDir(t *testing.T, pkgPath string) string {
1718
t.Helper()
18-
// Use -mod=readonly to bypass vendor directory and get the module cache path
19-
cmd := exec.Command("go", "list", "-mod=readonly", "-m", "-f", "{{.Dir}}", modulePath)
19+
cmd := exec.Command("go", "list", "-f", "{{.Dir}}", pkgPath)
2020
out, err := cmd.Output()
21-
require.NoError(t, err, "failed to find module %s", modulePath)
21+
require.NoError(t, err, "failed to find package %s", pkgPath)
2222
return strings.TrimSpace(string(out))
2323
}
2424

@@ -70,9 +70,9 @@ func getMockOpenAPISpec() *OpenAPISpec {
7070
}
7171

7272
func TestParseSubscriptionConfig(t *testing.T) {
73-
// Get the module path from go mod cache
74-
modulePath := getModulePath(t, "github.com/operator-framework/api")
75-
subscriptionTypesFile := filepath.Join(modulePath, "pkg/operators/v1alpha1/subscription_types.go")
73+
// Get the package directory containing subscription_types.go
74+
pkgDir := getPackageDir(t, "github.com/operator-framework/api/pkg/operators/v1alpha1")
75+
subscriptionTypesFile := filepath.Join(pkgDir, "subscription_types.go")
7676

7777
fields, err := parseSubscriptionConfig(subscriptionTypesFile)
7878
require.NoError(t, err, "should successfully parse SubscriptionConfig")

0 commit comments

Comments
 (0)