telegraf/agent/agent_test.go

112 lines
3.3 KiB
Go
Raw Permalink Normal View History

package agent
import (
2015-08-11 17:01:37 +00:00
"testing"
2015-10-23 17:23:08 +00:00
2016-01-20 18:57:35 +00:00
"github.com/influxdata/telegraf/internal/config"
2015-08-11 17:01:37 +00:00
// needing to load the plugins
2016-01-20 18:57:35 +00:00
_ "github.com/influxdata/telegraf/plugins/inputs/all"
// needing to load the outputs
2016-01-20 18:57:35 +00:00
_ "github.com/influxdata/telegraf/plugins/outputs/all"
"github.com/stretchr/testify/assert"
)
func TestAgent_OmitHostname(t *testing.T) {
c := config.NewConfig()
c.Agent.OmitHostname = true
_, err := NewAgent(c)
assert.NoError(t, err)
assert.NotContains(t, c.Tags, "host")
}
func TestAgent_LoadPlugin(t *testing.T) {
c := config.NewConfig()
2016-01-07 20:39:43 +00:00
c.InputFilters = []string{"mysql"}
err := c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ := NewAgent(c)
2016-01-07 20:39:43 +00:00
assert.Equal(t, 1, len(a.Config.Inputs))
c = config.NewConfig()
2016-01-07 20:39:43 +00:00
c.InputFilters = []string{"foo"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
2016-01-07 20:39:43 +00:00
assert.Equal(t, 0, len(a.Config.Inputs))
c = config.NewConfig()
2016-01-07 20:39:43 +00:00
c.InputFilters = []string{"mysql", "foo"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
2016-01-07 20:39:43 +00:00
assert.Equal(t, 1, len(a.Config.Inputs))
c = config.NewConfig()
2016-01-07 20:39:43 +00:00
c.InputFilters = []string{"mysql", "redis"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
2016-01-07 20:39:43 +00:00
assert.Equal(t, 2, len(a.Config.Inputs))
c = config.NewConfig()
2016-01-07 20:39:43 +00:00
c.InputFilters = []string{"mysql", "foo", "redis", "bar"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
2016-01-07 20:39:43 +00:00
assert.Equal(t, 2, len(a.Config.Inputs))
}
func TestAgent_LoadOutput(t *testing.T) {
c := config.NewConfig()
c.OutputFilters = []string{"influxdb"}
err := c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ := NewAgent(c)
assert.Equal(t, 2, len(a.Config.Outputs))
2016-01-07 17:52:46 +00:00
c = config.NewConfig()
c.OutputFilters = []string{"kafka"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
assert.Equal(t, 1, len(a.Config.Outputs))
c = config.NewConfig()
c.OutputFilters = []string{}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
assert.Equal(t, 3, len(a.Config.Outputs))
c = config.NewConfig()
c.OutputFilters = []string{"foo"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
assert.Equal(t, 0, len(a.Config.Outputs))
c = config.NewConfig()
c.OutputFilters = []string{"influxdb", "foo"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
assert.Equal(t, 2, len(a.Config.Outputs))
c = config.NewConfig()
c.OutputFilters = []string{"influxdb", "kafka"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
assert.Equal(t, 3, len(c.Outputs))
a, _ = NewAgent(c)
assert.Equal(t, 3, len(a.Config.Outputs))
c = config.NewConfig()
c.OutputFilters = []string{"influxdb", "foo", "kafka", "bar"}
err = c.LoadConfig("../internal/config/testdata/telegraf-agent.toml")
2016-01-07 17:52:46 +00:00
assert.NoError(t, err)
a, _ = NewAgent(c)
assert.Equal(t, 3, len(a.Config.Outputs))
}