diff --git a/pkg/run/files.go b/pkg/run/files.go index d88ca7e..1644b8f 100644 --- a/pkg/run/files.go +++ b/pkg/run/files.go @@ -37,7 +37,7 @@ type localFileAccessor struct { // NewLocalFileAccessor creates a FileAccessor of which content is the content // of a file in the local filesystem -func NewLocalFileAccessor(name, path string) *localFileAccessor { +func NewLocalFileAccessor(name, path string) FileAccessor { return &localFileAccessor{name: name, path: path} } @@ -55,12 +55,12 @@ type memFileAccessor struct { } // NewStringFileAccessor creates a FileAccessor that has a string as its content -func NewStringFileAccessor(name, content string) *memFileAccessor { +func NewStringFileAccessor(name, content string) FileAccessor { return &memFileAccessor{name: name, content: ([]byte)(content)} } // NewBytesFileAccessor creates a FileAccessor that has a byte buf as its content -func NewBytesFileAccessor(name string, content []byte) *memFileAccessor { +func NewBytesFileAccessor(name string, content []byte) FileAccessor { return &memFileAccessor{name: name, content: content} } diff --git a/tests/falco/miscs_test.go b/tests/falco/miscs_test.go index 2d9417e..fc1cc26 100644 --- a/tests/falco/miscs_test.go +++ b/tests/falco/miscs_test.go @@ -19,8 +19,13 @@ limitations under the License. package testfalco import ( + "fmt" + "github.com/falcosecurity/testing/pkg/run" + "github.com/falcosecurity/testing/tests/data/rules" "os" + "path/filepath" "testing" + "time" "github.com/falcosecurity/testing/pkg/falco" "github.com/falcosecurity/testing/tests" @@ -71,3 +76,37 @@ func TestFalco_Miscs_StartupFail(t *testing.T) { assert.Contains(t, res.Stderr(), "You must specify at least one rules file") }) } + +func TestFalco_Miscs_HotReload(t *testing.T) { + cwd, err := os.Getwd() + assert.NoError(t, err) + path := filepath.Join(cwd, "hot_reload_enabled.yaml") + _ = os.WriteFile(path, []byte(`watch_config_files: true`), 0700) + hotReloadCfg := run.NewLocalFileAccessor(path, path) + + t.Cleanup(func() { + _ = os.Remove(path) + }) + + go func() { + time.Sleep(2 * time.Second) + f, _ := os.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0700) + _, _ = f.WriteString(" \n\n") + _ = f.Close() + }() + + falcoRes := falco.Test( + tests.NewFalcoExecutableRunner(t), + falco.WithConfig(hotReloadCfg), + falco.WithRules(rules.SingleRule), + falco.WithStopAfter(5*time.Second), + falco.WithArgs("-o", "engine.kind=modern_ebpf"), + ) + assert.NoError(t, falcoRes.Err(), "%s", falcoRes.Stderr()) + assert.Equal(t, 0, falcoRes.ExitCode()) + + fmt.Println(falcoRes.Stderr()) + fmt.Println(falcoRes.Stdout()) + // We want to be sure that the hot reload was triggered + assert.Regexp(t, `SIGHUP received, restarting...`, falcoRes.Stderr()) +}