diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index 488e834fd..f56efe232 100644 --- a/internal/commands/result_test.go +++ b/internal/commands/result_test.go @@ -3,6 +3,7 @@ package commands import ( + "bytes" "encoding/json" "fmt" "io" @@ -1138,3 +1139,30 @@ func createEmptyResultSummary() *wrappers.ResultSummary { }, } } +func TestPrintPoliciesSummary_WhenNoRolViolated_ShouldNotContainPolicyViolation(t *testing.T) { + summary := &wrappers.ResultSummary{ + Policies: &wrappers.PolicyResponseModel{ + Status: "Success", + Policies: []wrappers.Policy{ + { + RulesViolated: []string{}, + }, + }, + BreakBuild: false, + }, + } + r, w, _ := os.Pipe() + old := os.Stdout + os.Stdout = w + + printPoliciesSummary(summary) + + w.Close() + os.Stdout = old + + var buf bytes.Buffer + io.Copy(&buf, r) + + output := buf.String() + assert.Assert(t, !strings.Contains(output, "Policy Management Violation "), "Output should not contain 'Policy Management Violation'") +} diff --git a/internal/commands/util/pr_test.go b/internal/commands/util/pr_test.go index 84ed0ec46..f2a86ae29 100644 --- a/internal/commands/util/pr_test.go +++ b/internal/commands/util/pr_test.go @@ -37,3 +37,10 @@ func TestIfScanRunning_WhenScanDone_ShouldReturnFalse(t *testing.T) { scanRunning, _ := isScanRunningOrQueued(scansMockWrapper, "ScanNotRunning") asserts.False(t, scanRunning) } + +func TestPRDecorationGithub_WhenNoViolatedPolicies_ShouldNotReturnPolicy(t *testing.T) { + prMockWrapper := &mock.PolicyMockWrapper{} + policyResponse, _, _ := prMockWrapper.EvaluatePolicy(nil) + prPolicy := policiesToPrPolicies(policyResponse) + asserts.True(t, len(prPolicy) == 0) +}