diff --git a/auditbeat/module/file_integrity/metricset_test.go b/auditbeat/module/file_integrity/metricset_test.go index 43fa02d15f7..c73af06c3d8 100644 --- a/auditbeat/module/file_integrity/metricset_test.go +++ b/auditbeat/module/file_integrity/metricset_test.go @@ -253,15 +253,13 @@ func TestIncludedExcludedFiles(t *testing.T) { config["recursive"] = true ms := mbtest.NewPushMetricSetV2(t, config) - go func() { - for _, f := range []string{"FILE.TXT", ".ssh/known_hosts", ".ssh/known_hosts.swp"} { - file := filepath.Join(dir, f) - err := ioutil.WriteFile(file, []byte("hello world"), 0600) - if err != nil { - t.Fatal(err) - } + for _, f := range []string{"FILE.TXT", ".ssh/known_hosts", ".ssh/known_hosts.swp"} { + file := filepath.Join(dir, f) + err := ioutil.WriteFile(file, []byte("hello world"), 0600) + if err != nil { + t.Fatal(err) } - }() + } events := mbtest.RunPushMetricSetV2(10*time.Second, 3, ms) for _, e := range events { @@ -278,14 +276,16 @@ func TestIncludedExcludedFiles(t *testing.T) { if !assert.Len(t, events, len(wanted)) { return } + + got := map[string]bool{} for _, e := range events { event := e.MetricSetFields path, err := event.GetValue("file.path") - if assert.NoError(t, err) { - _, ok := wanted[path.(string)] - assert.True(t, ok) + if assert.NoError(t, err, "Failed to read file.path field") { + got[path.(string)] = true } } + assert.Equal(t, wanted, got) } func getConfig(path ...string) map[string]interface{} {