Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahCx committed Sep 18, 2024
1 parent 6a2ce91 commit dfd199c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions internal/commands/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package commands

import (
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -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)

Check failure on line 1164 in internal/commands/result_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `io.Copy` is not checked (errcheck)

output := buf.String()
assert.Assert(t, !strings.Contains(output, "Policy Management Violation "), "Output should not contain 'Policy Management Violation'")
}
7 changes: 7 additions & 0 deletions internal/commands/util/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit dfd199c

Please sign in to comment.