Skip to content

Commit

Permalink
fix bug with loading plugins in shim with no config (influxdata#7816)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored Jul 10, 2020
1 parent 37f12ec commit db02ae5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion plugins/common/shim/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func createPluginsWithTomlConfig(md toml.MetaData, conf config) (loadedConfig, e
// have registered themselves with the registry. This makes loading plugins
// without having to define a config dead easy.
func DefaultImportedPlugins() (config, error) {
conf := config{}
conf := config{
Inputs: map[string][]toml.Primitive{},
Processors: map[string][]toml.Primitive{},
Outputs: map[string][]toml.Primitive{},
}
for name := range inputs.Inputs {
conf.Inputs[name] = []toml.Primitive{}
return conf, nil
Expand Down
10 changes: 10 additions & 0 deletions plugins/common/shim/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ func TestLoadConfig(t *testing.T) {
require.Equal(t, "xxxxxxxxxx", inp.SecretToken)
require.Equal(t, `test"\test`, inp.SecretValue)
}

func TestDefaultImportedPluginsSelfRegisters(t *testing.T) {
inputs.Add("test", func() telegraf.Input {
return &testInput{}
})

cfg, err := LoadConfig(nil)
require.NoError(t, err)
require.Equal(t, "test", cfg.Input.Description())
}
2 changes: 1 addition & 1 deletion plugins/common/shim/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (i *testInput) SampleConfig() string {
}

func (i *testInput) Description() string {
return ""
return "test"
}

func (i *testInput) Gather(acc telegraf.Accumulator) error {
Expand Down

0 comments on commit db02ae5

Please sign in to comment.