Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Raghav Kaul <raghavkaul@google.com>
  • Loading branch information
raghavkaul authored and jeffmendoza committed Nov 21, 2023
1 parent 2531796 commit 4b3f718
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/enforce/enforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,42 @@ func (m MockGhClients) Get(i int64) (*github.Client, error) {

func (m MockGhClients) LogCacheSize() {}

func TestSkipEmptyRepositories(t *testing.T) {
policiesGetPolicies = func() []policydef.Policy {
return []policydef.Policy{
pol{},
}
}

isRepositoryEmpty = func(ctx context.Context, c *github.Client, s1, s2, s3 string) (bool, error) {
return true, nil
}

repo := "fake-repo"

tests := []struct {
Desc string
}{
{
Desc: "test skip a single empty repository",
},
}

for _, test := range tests {
t.Run(test.Desc, func(t *testing.T) {
enforceResults, err := runPoliciesReal(context.Background(), nil, "", repo, true, "")

if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

if len(enforceResults) != 0 {
t.Errorf("expected no policy results, got %+v\n", enforceResults)
}
})
}
}

func TestRunPolicies(t *testing.T) {
policiesGetPolicies = func() []policydef.Policy {
return []policydef.Policy{
Expand All @@ -107,6 +143,9 @@ func TestRunPolicies(t *testing.T) {
closeCalled = true
return nil
}
isRepositoryEmpty = func(ctx context.Context, c *github.Client, s1, s2, s3 string) (bool, error) {
return false, nil
}
repo := "fake-repo"
tests := []struct {
Name string
Expand Down

0 comments on commit 4b3f718

Please sign in to comment.