Skip to content

Commit 259b911

Browse files
author
Matt Cadorette
authored
fix: failing tests due to transient data states (#1608)
1 parent 7971108 commit 259b911

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

integration/alert_list_test.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package integration
2222
import (
2323
"encoding/json"
2424
"strconv"
25+
"strings"
2526
"testing"
2627

2728
"github.com/lacework/go-sdk/api"
@@ -106,15 +107,37 @@ func TestAlertListSeverityBad(t *testing.T) {
106107
}
107108

108109
func TestAlertListSeverityHighAndCritical(t *testing.T) {
109-
out, err, exitcode := LaceworkCLIWithTOMLConfig("alert", "list", "--severity", "high", "--range", "last week")
110-
// I found that sometimes tech-ally sub account does not have critical
111-
//assert.Contains(t, out.String(), "Critical")
112-
assert.Contains(t, out.String(), "High")
113-
assert.NotContains(t, out.String(), "Low")
114-
assert.NotContains(t, out.String(), "Medium")
115-
assert.NotContains(t, out.String(), "Info")
116-
assert.Empty(t, err.String(), "STDERR should be empty")
117-
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
110+
// Sometimes tech-ally doesn't have critical or high alerts, so those get skipped
111+
// this is a strange but required workaround since these tests run against real data
112+
// we expect to always find medium low and info
113+
t.Run("should be able to find critical alerts", func(t *testing.T) {
114+
out, err, exitcode := LaceworkCLIWithTOMLConfig("alert", "list", "--severity", "critical", "--range", "last week")
115+
if strings.Contains(out.String(), "Critical") {
116+
assert.Contains(t, out.String(), "Critical")
117+
assert.Empty(t, err.String(), "STDERR should be empty")
118+
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
119+
} else {
120+
t.Skip()
121+
}
122+
})
123+
t.Run("should be able to find high alerts", func(t *testing.T) {
124+
out, err, exitcode := LaceworkCLIWithTOMLConfig("alert", "list", "--severity", "high", "--range", "last week")
125+
if strings.Contains(out.String(), "high") {
126+
assert.Contains(t, out.String(), "high")
127+
assert.Empty(t, err.String(), "STDERR should be empty")
128+
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
129+
} else {
130+
t.Skip()
131+
}
132+
})
133+
t.Run("should be able to find low,medium,info alerts", func(t *testing.T) {
134+
out, err, exitcode := LaceworkCLIWithTOMLConfig("alert", "list", "--severity", "high", "--range", "last week")
135+
assert.NotContains(t, out.String(), "Low")
136+
assert.NotContains(t, out.String(), "Medium")
137+
assert.NotContains(t, out.String(), "Info")
138+
assert.Empty(t, err.String(), "STDERR should be empty")
139+
assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one")
140+
})
118141
}
119142

120143
func TestAlertListStatusBad(t *testing.T) {

0 commit comments

Comments
 (0)