Skip to content

Commit

Permalink
closer
Browse files Browse the repository at this point in the history
  • Loading branch information
roryscarson committed Oct 11, 2023
1 parent acf62ce commit ab83f28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/policies/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pkg/policies/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")

Check failure on line 225 in pkg/policies/catalog/catalog_test.go

View workflow job for this annotation

GitHub Actions / test

cannot use mockRepos{} (value of type mockRepos) as *github.Client value in argument to check
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand Down

0 comments on commit ab83f28

Please sign in to comment.