2015-05-22 23:45:14 +00:00
|
|
|
package telegraf
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-08-11 15:50:36 +00:00
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
2015-08-11 17:01:37 +00:00
|
|
|
"testing"
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-08-11 17:01:37 +00:00
|
|
|
// needing to load the plugins
|
2015-08-11 15:50:36 +00:00
|
|
|
_ "github.com/influxdb/telegraf/plugins/all"
|
2015-09-22 01:38:57 +00:00
|
|
|
// needing to load the outputs
|
2015-10-17 06:11:12 +00:00
|
|
|
_ "github.com/influxdb/telegraf/outputs/all"
|
2015-08-11 15:50:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAgent_LoadPlugin(t *testing.T) {
|
|
|
|
|
|
|
|
// load a dedicated configuration file
|
|
|
|
config, _ := LoadConfig("./testdata/telegraf-agent.toml")
|
|
|
|
a, _ := NewAgent(config)
|
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
pluginsEnabled, _ := a.LoadPlugins([]string{"mysql"}, config)
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 1, len(pluginsEnabled))
|
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"foo"}, config)
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 0, len(pluginsEnabled))
|
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "foo"}, config)
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 1, len(pluginsEnabled))
|
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "redis"}, config)
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 2, len(pluginsEnabled))
|
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "foo", "redis", "bar"}, config)
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 2, len(pluginsEnabled))
|
2015-09-22 01:38:57 +00:00
|
|
|
}
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
func TestAgent_LoadOutput(t *testing.T) {
|
|
|
|
// load a dedicated configuration file
|
|
|
|
config, _ := LoadConfig("./testdata/telegraf-agent.toml")
|
|
|
|
a, _ := NewAgent(config)
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ := a.LoadOutputs([]string{"influxdb"}, config)
|
|
|
|
assert.Equal(t, 1, len(outputsEnabled))
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ = a.LoadOutputs([]string{}, config)
|
|
|
|
assert.Equal(t, 2, len(outputsEnabled))
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ = a.LoadOutputs([]string{"foo"}, config)
|
|
|
|
assert.Equal(t, 0, len(outputsEnabled))
|
2015-09-22 01:38:57 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "foo"}, config)
|
|
|
|
assert.Equal(t, 1, len(outputsEnabled))
|
2015-09-22 01:38:57 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "kafka"}, config)
|
|
|
|
assert.Equal(t, 2, len(outputsEnabled))
|
2015-09-22 01:38:57 +00:00
|
|
|
|
2015-10-17 06:11:12 +00:00
|
|
|
outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "foo", "kafka", "bar"}, config)
|
|
|
|
assert.Equal(t, 2, len(outputsEnabled))
|
|
|
|
}
|