Skip to content

Commit

Permalink
test: assert success on determinism check
Browse files Browse the repository at this point in the history
Also runs gofmt over scan.go
  • Loading branch information
sublimino committed Nov 7, 2019
1 parent 0b06866 commit fb31cc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 3 additions & 4 deletions cmd/kubesec/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func (e *ScanFailedValidationError) Error() string {

var debug bool


func init() {
scanCmd.Flags().BoolVar(&debug, "debug", false, "turn on debug logs")
rootCmd.AddCommand(scanCmd)
Expand Down Expand Up @@ -77,11 +76,11 @@ var scanCmd = &cobra.Command{

// Sort reports into custom order
for _, r := range reports {
if (r.Valid) {
if ( len(r.Scoring.Critical) >1 ) {
if r.Valid {
if len(r.Scoring.Critical) > 1 {
sort.Sort(ruler.RuleRefCustomOrder(r.Scoring.Critical))
}
if ( len(r.Scoring.Advise) >1 ) {
if len(r.Scoring.Advise) > 1 {
sort.Sort(ruler.RuleRefCustomOrder(r.Scoring.Advise))
}
}
Expand Down
19 changes: 14 additions & 5 deletions test/1_cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ teardown() {
done
}

@test "returns a ordered point score present" {
@test "returns an ordered point score for all responses" {
run \
_app ${TEST_DIR}/asset/score-2-pod-serviceaccount.yml

Expand All @@ -159,18 +159,27 @@ teardown() {
done
}

@test "report deterministic - same output for 3 runs" {
@test "returns deterministic report output" {
run \
_app ${TEST_DIR}/asset/score-2-pod-serviceaccount.yml
RUN_1_SIGNATURE=$(echo "$output" | sha1sum)

assert_success

RUN_1_SIGNATURE=$(echo "${output}" | sha1sum)

run \
_app ${TEST_DIR}/asset/score-2-pod-serviceaccount.yml
RUN_2_SIGNATURE=$(echo "$output" | sha1sum)

assert_success

RUN_2_SIGNATURE=$(echo "${output}" | sha1sum)

run \
_app ${TEST_DIR}/asset/score-2-pod-serviceaccount.yml
RUN_3_SIGNATURE=$(echo "$output" | sha1sum)

assert_success

RUN_3_SIGNATURE=$(echo "${output}" | sha1sum)

[ "${RUN_1_SIGNATURE}" == "${RUN_2_SIGNATURE}" ]
[ "${RUN_1_SIGNATURE}" == "${RUN_3_SIGNATURE}" ]
Expand Down

0 comments on commit fb31cc0

Please sign in to comment.