Skip to content

Commit

Permalink
Fix filebeat config merging + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Jul 12, 2016
1 parent 07a373f commit 4b992ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 5 additions & 3 deletions filebeat/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ func mergeConfigFiles(configFiles []string, config *Config) error {
for _, file := range configFiles {
logp.Info("Additional configs loaded from: %s", file)

tmpConfig := &Config{}
cfgfile.Read(tmpConfig, file)
tmpConfig := struct {
Filebeat Config
}{}
cfgfile.Read(&tmpConfig, file)

config.Prospectors = append(config.Prospectors, tmpConfig.Prospectors...)
config.Prospectors = append(config.Prospectors, tmpConfig.Filebeat.Prospectors...)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions filebeat/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestReadConfig2(t *testing.T) {
err = cfgfile.Read(config, absPath+"/config2.yml")
assert.Nil(t, err)

assert.Equal(t, uint64(0), config.Filebeat.SpoolSize)
assert.Equal(t, uint64(0), config.SpoolSize)
}

func TestGetConfigFiles_File(t *testing.T) {
Expand Down Expand Up @@ -94,5 +94,5 @@ func TestMergeConfigFiles(t *testing.T) {
config := &Config{}
mergeConfigFiles(files, config)

assert.Equal(t, 4, len(config.Filebeat.Prospectors))
assert.Equal(t, 4, len(config.Prospectors))
}
16 changes: 9 additions & 7 deletions filebeat/spooler/spooler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import (
"github.com/stretchr/testify/assert"
)

func load(t *testing.T, in string) cfg.FilebeatConfig {
func load(t *testing.T, in string) *cfg.Config {
yaml, err := common.NewConfigWithYAML([]byte(in), "")
if err != nil {
t.Fatalf("Failed to parse config input: %v", err)
}

config := cfg.DefaultConfig
err = yaml.Unpack(&config)
tmpConfig := struct {
Filebeat cfg.Config
}{cfg.DefaultConfig}
err = yaml.Unpack(&tmpConfig)
if err != nil {
t.Fatalf("Failed to unpack config: %v", err)
}

return config.Filebeat
return &tmpConfig.Filebeat
}

func TestNewSpoolerDefaultConfig(t *testing.T) {
Expand All @@ -33,13 +35,13 @@ func TestNewSpoolerDefaultConfig(t *testing.T) {
spooler, err := New(config, nil)

assert.NoError(t, err)
assert.Equal(t, cfg.DefaultConfig.Filebeat.SpoolSize, spooler.config.spoolSize)
assert.Equal(t, cfg.DefaultConfig.Filebeat.IdleTimeout, spooler.config.idleTimeout)
assert.Equal(t, cfg.DefaultConfig.SpoolSize, spooler.config.spoolSize)
assert.Equal(t, cfg.DefaultConfig.IdleTimeout, spooler.config.idleTimeout)
}

func TestNewSpoolerSpoolSize(t *testing.T) {
spoolSize := uint64(19)
config := cfg.FilebeatConfig{SpoolSize: spoolSize}
config := &cfg.Config{SpoolSize: spoolSize}
spooler, err := New(config, nil)

assert.NoError(t, err)
Expand Down

0 comments on commit 4b992ae

Please sign in to comment.