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