Skip to content

Commit 11185cb

Browse files
Rohith-Rajupoiana
authored andcommitted
Added new tests for -L (List all rules) command
Signed-off-by: Rohith-Raju <[email protected]>
1 parent 7e2011f commit 11185cb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/falco/commands_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/falcosecurity/testing/pkg/falco"
2626
"github.com/falcosecurity/testing/tests"
2727
"github.com/falcosecurity/testing/tests/data/outputs"
28+
"github.com/falcosecurity/testing/tests/data/rules"
2829

2930
"github.com/stretchr/testify/assert"
3031
)
@@ -155,3 +156,33 @@ func TestFalco_Print_IgnoredEvents(t *testing.T) {
155156
assert.NoError(t, res.Err(), "%s", res.Stderr())
156157
assert.Equal(t, res.ExitCode(), 0)
157158
}
159+
160+
func TestFalco_Print_Rules(t *testing.T) {
161+
t.Parallel()
162+
checkDefaultConfig(t)
163+
runner := tests.NewFalcoExecutableRunner(t)
164+
t.Run("valid-rules", func(t *testing.T) {
165+
t.Parallel()
166+
res := falco.Test(
167+
runner,
168+
falco.WithArgs("-L"),
169+
falco.WithRules(rules.DetectConnectUsingIn, rules.ListAppend, rules.CatchallOrder),
170+
)
171+
rules := []string{"Open From Cat", "Localhost connect", "open_dev_null", "dev_null"}
172+
for _, rule := range rules {
173+
assert.Contains(t, res.Stdout(), rule)
174+
}
175+
assert.NoError(t, res.Err(), "%s", res.Stderr())
176+
assert.Equal(t, res.ExitCode(), 0)
177+
})
178+
t.Run("invalid-rules", func(t *testing.T) {
179+
t.Parallel()
180+
res := falco.Test(
181+
runner,
182+
falco.WithArgs("-L"),
183+
falco.WithRules(rules.InvalidRuleOutput),
184+
)
185+
assert.Error(t, res.Err(), "%s", res.Stderr())
186+
assert.Equal(t, res.ExitCode(), 1)
187+
})
188+
}

0 commit comments

Comments
 (0)