Skip to content

Commit ef808de

Browse files
author
Matt Cadorette
authored
fix: policy severity test correct test criteria (#1614)
1 parent 5440c57 commit ef808de

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

integration/policy_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package integration
2121

2222
import (
2323
"bytes"
24+
"encoding/json"
2425
"errors"
2526
"fmt"
2627
"os"
@@ -326,12 +327,31 @@ func TestPolicyBadSeverity(t *testing.T) {
326327

327328
}
328329

330+
type PolicyDetail struct {
331+
Severity string `json:"severity"`
332+
PolicyID string `json:"policyId"`
333+
}
334+
329335
func TestPolicySeverityCritical(t *testing.T) {
330-
out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "list", "--severity", "critical")
331-
assert.Contains(t, out.String(), "lacework-global-8")
332-
assert.NotContains(t, out.String(), "high")
336+
out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "list", "--severity", "critical", "--json")
333337
assert.Empty(t, err.String(), "STDERR should be empty")
334338
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
339+
340+
var details []PolicyDetail
341+
assert.NoError(t, json.Unmarshal(out.Bytes(), &details))
342+
343+
found := false
344+
notCritical := false
345+
for _, policy := range details {
346+
if policy.PolicyID == "lacework-global-8" {
347+
found = true
348+
}
349+
if policy.Severity != "critical" {
350+
notCritical = true
351+
}
352+
}
353+
assert.True(t, found, "lacework-global-8 should have been found in policy list of severity critical")
354+
assert.False(t, notCritical, "only policies with severity critical should have been found")
335355
}
336356

337357
func TestPolicyShowHelp(t *testing.T) {

0 commit comments

Comments
 (0)