diff --git a/pkg/policies/catalog/catalog.go b/pkg/policies/catalog/catalog.go index cbd27f94..8dcfde40 100644 --- a/pkg/policies/catalog/catalog.go +++ b/pkg/policies/catalog/catalog.go @@ -80,6 +80,8 @@ var configFetchConfig func(context.Context, *github.Client, string, string, stri var configIsEnabled func(ctx context.Context, o config.OrgOptConfig, orc, r config.RepoOptConfig, c *github.Client, owner, repo string) (bool, error) +//var catalogExists func(ctx context.Context, c *github.Client, owner, repo string) (bool, error) + func init() { configFetchConfig = config.FetchConfig configIsEnabled = config.IsEnabled diff --git a/pkg/policies/catalog/catalog_test.go b/pkg/policies/catalog/catalog_test.go index b414b077..37e6e3db 100644 --- a/pkg/policies/catalog/catalog_test.go +++ b/pkg/policies/catalog/catalog_test.go @@ -28,6 +28,11 @@ import ( type mockRepos struct{} type MockGhClient struct{} +var catalogExists func(ctx context.Context, c *github.Client, owner, repo string) (bool, error) + +func (m mockRepos) catalogExists(ctx context.Context, c *github.Client, owner, repo string) (bool, error) { + return catalogExists(ctx, c, owner, repo) +} func (m MockGhClient) Get(i int64) (*github.Client, error) { return github.NewClient(&http.Client{}), nil } @@ -201,6 +206,22 @@ func TestCheck(t *testing.T) { c *github.Client, owner, repo string) (bool, error) { return test.configEnabled, nil } + catalogExists = func(ctx context.Context, c *github.Client, owner, repo string) (bool, error) { + + path := "/contents/catalog-info.yaml" + opts := &github.RepositoryContentGetOptions{ + Ref: "master", + } + + //GetContentsURL returns the ContentsURL field if it's non-nil, zero value otherwise. + _, _, _, err := c.Repositories.GetContents(ctx, owner, repo, path, opts) + if err != nil { + t.Fatalf("Unexpected error checking for file: %v", err) + return false, nil + } + + return true, nil + } res, err := check(context.Background(), mockRepos{}, nil, "", "thisrepo") if err != nil { t.Fatalf("Unexpected error: %v", err)