Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libbeat/outputs/fileout/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type fileOutConfig struct {

func defaultConfig() fileOutConfig {
return fileOutConfig{
Path: &PathFormatString{},
NumberOfFiles: 7,
RotateEveryKb: 10 * 1024,
Permissions: 0600,
Expand Down
1 change: 1 addition & 0 deletions libbeat/outputs/fileout/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestConfig(t *testing.T) {
config: config.MustNewConfigFrom([]byte(`{ }`)),
assertion: func(t *testing.T, actual *fileOutConfig, err error) {
expectedConfig := &fileOutConfig{
Path: &PathFormatString{},
NumberOfFiles: 7,
RotateEveryKb: 10 * 1024,
Permissions: 0600,
Expand Down
4 changes: 4 additions & 0 deletions libbeat/outputs/fileout/pathformatstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package fileout

import (
"fmt"
"os"
"strings"
"time"
Expand All @@ -44,6 +45,9 @@ func (fs *PathFormatString) Run(timestamp time.Time) (string, error) {
placeholderEvent := &beat.Event{
Timestamp: timestamp,
}
if fs.efs == nil {
return "", fmt.Errorf("path format string is nil; check if `path` option is configured correctly")
}
return fs.efs.Run(placeholderEvent)
}

Expand Down
12 changes: 12 additions & 0 deletions libbeat/outputs/fileout/pathformatstring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/elastic-agent-libs/config"
)

func TestCheckNilDoesntPanic(t *testing.T) {
newCfg := config.NewConfig()
handler, err := readConfig(newCfg)
require.NoError(t, err)
_, err = handler.Path.Run(time.Now())
require.Error(t, err)

}

func TestPathFormatString(t *testing.T) {
tests := []struct {
title string
Expand Down