From 4b3f718a24c914794bd63b27a6aee22b044fd9e0 Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Tue, 7 Nov 2023 14:31:45 +0000 Subject: [PATCH] Fix tests Signed-off-by: Raghav Kaul --- pkg/enforce/enforce_test.go | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/enforce/enforce_test.go b/pkg/enforce/enforce_test.go index a45fda66..442ca446 100644 --- a/pkg/enforce/enforce_test.go +++ b/pkg/enforce/enforce_test.go @@ -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{ @@ -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