@@ -21,6 +21,7 @@ package integration
2121
2222import (
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+
329335func 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
337357func TestPolicyShowHelp (t * testing.T ) {
0 commit comments