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
|
|
|
|
// _ "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-09-22 01:38:57 +00:00
|
|
|
pluginsEnabled, _ := a.LoadPlugins([]string{"mysql"})
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 1, len(pluginsEnabled))
|
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"foo"})
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 0, len(pluginsEnabled))
|
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "foo"})
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 1, len(pluginsEnabled))
|
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "redis"})
|
2015-08-11 15:50:36 +00:00
|
|
|
assert.Equal(t, 2, len(pluginsEnabled))
|
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
pluginsEnabled, _ = a.LoadPlugins([]string{"mysql", "foo", "redis", "bar"})
|
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-09-22 01:38:57 +00:00
|
|
|
// TODO enable these unit tests, currently disabled because of a circular import
|
|
|
|
// 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-09-22 01:38:57 +00:00
|
|
|
// outputsEnabled, _ := a.LoadOutputs([]string{"influxdb"})
|
|
|
|
// assert.Equal(t, 1, len(outputsEnabled))
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
// outputsEnabled, _ = a.LoadOutputs([]string{})
|
|
|
|
// assert.Equal(t, 2, len(outputsEnabled))
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-09-22 01:38:57 +00:00
|
|
|
// outputsEnabled, _ = a.LoadOutputs([]string{"foo"})
|
|
|
|
// assert.Equal(t, 0, len(outputsEnabled))
|
|
|
|
|
|
|
|
// outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "foo"})
|
|
|
|
// assert.Equal(t, 1, len(outputsEnabled))
|
|
|
|
|
|
|
|
// outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "kafka"})
|
|
|
|
// assert.Equal(t, 2, len(outputsEnabled))
|
|
|
|
|
|
|
|
// outputsEnabled, _ = a.LoadOutputs([]string{"influxdb", "foo", "kafka", "bar"})
|
|
|
|
// assert.Equal(t, 2, len(outputsEnabled))
|
|
|
|
// }
|
2015-08-11 15:50:36 +00:00
|
|
|
|
2015-04-06 16:32:10 +00:00
|
|
|
/*
|
2015-04-04 05:13:35 +00:00
|
|
|
func TestAgent_DrivesMetrics(t *testing.T) {
|
|
|
|
var (
|
|
|
|
plugin plugins.MockPlugin
|
|
|
|
)
|
|
|
|
|
|
|
|
defer plugin.AssertExpectations(t)
|
|
|
|
defer metrics.AssertExpectations(t)
|
|
|
|
|
|
|
|
a := &Agent{
|
|
|
|
plugins: []plugins.Plugin{&plugin},
|
|
|
|
Config: &Config{},
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:32:10 +00:00
|
|
|
plugin.On("Add", "foo", 1.2, nil).Return(nil)
|
|
|
|
plugin.On("Add", "bar", 888, nil).Return(nil)
|
2015-04-04 05:13:35 +00:00
|
|
|
|
|
|
|
err := a.crank()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAgent_AppliesTags(t *testing.T) {
|
2015-04-01 16:34:32 +00:00
|
|
|
var (
|
|
|
|
plugin plugins.MockPlugin
|
|
|
|
metrics MockMetrics
|
|
|
|
)
|
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
defer plugin.AssertExpectations(t)
|
|
|
|
defer metrics.AssertExpectations(t)
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
a := &Agent{
|
|
|
|
plugins: []plugins.Plugin{&plugin},
|
|
|
|
metrics: &metrics,
|
|
|
|
Config: &Config{
|
|
|
|
Tags: map[string]string{
|
|
|
|
"dc": "us-west-1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
m1 := cypress.Metric()
|
|
|
|
m1.Add("name", "foo")
|
|
|
|
m1.Add("value", 1.2)
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
msgs := []*cypress.Message{m1}
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
m2 := cypress.Metric()
|
|
|
|
m2.Timestamp = m1.Timestamp
|
|
|
|
m2.Add("name", "foo")
|
|
|
|
m2.Add("value", 1.2)
|
|
|
|
m2.AddTag("dc", "us-west-1")
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
plugin.On("Read").Return(msgs, nil)
|
|
|
|
metrics.On("Receive", m2).Return(nil)
|
2015-04-01 16:34:32 +00:00
|
|
|
|
2015-04-04 05:13:35 +00:00
|
|
|
err := a.crank()
|
|
|
|
require.NoError(t, err)
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|
2015-08-11 17:01:37 +00:00
|
|
|
*/
|