diff --git a/pkg/falco/tester_options.go b/pkg/falco/tester_options.go index ff92f84..e994ee6 100644 --- a/pkg/falco/tester_options.go +++ b/pkg/falco/tester_options.go @@ -61,17 +61,30 @@ func WithConfig(f run.FileAccessor) TestOption { // WithEnabledTags runs Falco with enabled rules tags through the `-t` option. func WithEnabledTags(tags ...string) TestOption { - return withMultipleArgValues("-t", tags...) + return func(o *testOptions) { + o.args = append(o.args, "-o", "rules[].disable.rule=*") + for _, t := range tags { + o.args = append(o.args, "-o", "rules[].enable.tag="+t) + } + } } // WithDisabledTags runs Falco with disabled rules tags through the `-T` option. func WithDisabledTags(tags ...string) TestOption { - return withMultipleArgValues("-T", tags...) + return func(o *testOptions) { + for _, t := range tags { + o.args = append(o.args, "-o", "rules[].disable.tag="+t) + } + } } -// WithDisabledRules runs Falco with disabled rules through the `-D` option. +// WithDisabledRules runs Falco with disabled rules through the `rules:` config option. func WithDisabledRules(rules ...string) TestOption { - return withMultipleArgValues("-D", rules...) + return func(o *testOptions) { + for _, r := range rules { + o.args = append(o.args, "-o", "rules[].disable.rule="+r) + } + } } // WithEnabledSources runs Falco with enabled event sources through the `--enable-source` option. diff --git a/tests/falco/legacy_test.go b/tests/falco/legacy_test.go index 6007caa..f4d3a2d 100644 --- a/tests/falco/legacy_test.go +++ b/tests/falco/legacy_test.go @@ -105,21 +105,6 @@ func TestFalco_Legacy_Endswith(t *testing.T) { assert.Equal(t, 0, res.ExitCode()) } -func TestFalco_Legacy_DisabledAndEnabledRules1(t *testing.T) { - t.Parallel() - checkConfig(t) - res := falco.Test( - tests.NewFalcoExecutableRunner(t), - falco.WithRules(rules.SingleRule), - falco.WithDisabledTags("a"), - falco.WithEnabledTags("a"), - falco.WithCaptureFile(captures.CatWrite), - ) - assert.Regexp(t, `Error: You can not specify both disabled .-D/-T. and enabled .-t. rules`, res.Stderr()) - assert.Error(t, res.Err(), "%s", res.Stderr()) - assert.Equal(t, 1, res.ExitCode()) -} - func TestFalco_Legacy_StdoutOutputStrict(t *testing.T) { t.Parallel() res := falco.Test( @@ -1582,21 +1567,6 @@ func TestFalco_Legacy_InvalidAppendRuleMultipleDocs(t *testing.T) { assert.Equal(t, 1, res.ExitCode()) } -func TestFalco_Legacy_DisabledAndEnabledRules2(t *testing.T) { - t.Parallel() - checkConfig(t) - res := falco.Test( - tests.NewFalcoExecutableRunner(t), - falco.WithRules(rules.SingleRule), - falco.WithDisabledRules("open.*"), - falco.WithEnabledTags("a"), - falco.WithCaptureFile(captures.CatWrite), - ) - assert.Regexp(t, `Error: You can not specify both disabled .-D/-T. and enabled .-t. rules`, res.Stderr()) - assert.Error(t, res.Err(), "%s", res.Stderr()) - assert.Equal(t, 1, res.ExitCode()) -} - func TestFalco_Legacy_RunTagsAb(t *testing.T) { t.Parallel() checkConfig(t)