Skip to content

Commit

Permalink
Fix Filestream tests
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Dec 12, 2024
1 parent 1e92ff2 commit c1693f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions filebeat/input/filestream/fswatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ scanner:
paths := []string{filepath.Join(dir, "*.log")}
cfgStr := `
scanner:
fingerprint.enabled: false
check_interval: 10ms
`

Expand Down Expand Up @@ -260,6 +261,7 @@ scanner:
paths := []string{filepath.Join(dir, "*.log")}
cfgStr := `
scanner:
fingerprint.enabled: false
check_interval: 50ms
`

Expand Down Expand Up @@ -370,6 +372,7 @@ scanner:
}
cfgStr := `
scanner:
fingerprint.enabled: false
check_interval: 100ms
`

Expand Down Expand Up @@ -615,6 +618,7 @@ scanner:
name: "returns no symlink if the original file is excluded",
cfgStr: `
scanner:
fingerprint.enabled: false
exclude_files: ['.*exclude.*', '.*traveler.*']
symlinks: true
`,
Expand Down Expand Up @@ -661,6 +665,7 @@ scanner:
name: "returns no included symlink if the original file is not included",
cfgStr: `
scanner:
fingerprint.enabled: false
include_files: ['.*include.*', '.*portal.*']
symlinks: true
`,
Expand All @@ -678,6 +683,7 @@ scanner:
name: "returns an included symlink if the original file is included",
cfgStr: `
scanner:
fingerprint.enabled: false
include_files: ['.*include.*', '.*portal.*', '.*traveler.*']
symlinks: true
`,
Expand Down
23 changes: 16 additions & 7 deletions filebeat/input/filestream/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package filestream

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -35,12 +34,17 @@ type testFileIdentifierConfig struct {
}

func TestFileIdentifier(t *testing.T) {
t.Run("default file identifier", func(t *testing.T) {
identifier, err := newFileIdentifier(nil, "")
t.Run("native file identifier", func(t *testing.T) {
cfg := conf.MustNewConfigFrom(`native: ~`)
ns := conf.Namespace{}
if err := cfg.Unpack(&ns); err != nil {
t.Fatalf("cannot unpack config into conf.Namespace: %s", err)
}
identifier, err := newFileIdentifier(&ns, "")
require.NoError(t, err)
assert.Equal(t, DefaultIdentifierName, identifier.Name())

tmpFile, err := ioutil.TempFile("", "test_file_identifier_native")
tmpFile, err := os.CreateTemp("", "test_file_identifier_native")
if err != nil {
t.Fatalf("cannot create temporary file for test: %v", err)
}
Expand All @@ -59,12 +63,17 @@ func TestFileIdentifier(t *testing.T) {
assert.Equal(t, identifier.Name()+"::"+file.GetOSState(fi).String(), src.Name())
})

t.Run("default file identifier with suffix", func(t *testing.T) {
identifier, err := newFileIdentifier(nil, "my-suffix")
t.Run("native file identifier with suffix", func(t *testing.T) {
cfg := conf.MustNewConfigFrom(`native: ~`)
ns := conf.Namespace{}
if err := cfg.Unpack(&ns); err != nil {
t.Fatalf("cannot unpack config into conf.Namespace: %s", err)
}
identifier, err := newFileIdentifier(&ns, "my-suffix")
require.NoError(t, err)
assert.Equal(t, DefaultIdentifierName, identifier.Name())

tmpFile, err := ioutil.TempFile("", "test_file_identifier_native")
tmpFile, err := os.CreateTemp("", "test_file_identifier_native")
if err != nil {
t.Fatalf("cannot create temporary file for test: %v", err)
}
Expand Down
3 changes: 3 additions & 0 deletions filebeat/input/filestream/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func BenchmarkFilestream(b *testing.B) {
cfg := `
type: filestream
prospector.scanner.check_interval: 1s
prospector.scanner.fingerprint.enabled: false
paths:
- ` + filename + `
`
Expand Down Expand Up @@ -91,6 +92,7 @@ paths:
cfg := `
type: filestream
prospector.scanner.check_interval: 1s
prospector.scanner.fingerprint.enabled: false
paths:
- ` + ingestPath + `
`
Expand Down Expand Up @@ -146,6 +148,7 @@ func TestTakeOverTags(t *testing.T) {
cfg := fmt.Sprintf(`
type: filestream
prospector.scanner.check_interval: 1s
prospector.scanner.fingerprint.enabled: false
take_over: %t
paths:
- %s`, testCase.takeOver, filename)
Expand Down

0 comments on commit c1693f2

Please sign in to comment.