fix bug with loading plugins in shim with no config (#7816)

This commit is contained in:
Steven Soroka 2020-07-10 15:05:26 -04:00 committed by GitHub
parent 37f12ec6ea
commit db02ae5829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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())
}

View File

@ -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 {