readability tweak

This commit is contained in:
Max U 2018-06-28 15:56:36 -07:00
parent 885193bc8f
commit 674b9578d7
10 changed files with 31 additions and 51 deletions

View File

@ -143,11 +143,10 @@ func TestConfig_LoadDirectory(t *testing.T) {
"Testdata did not produce correct memcached metadata.") "Testdata did not produce correct memcached metadata.")
ex := inputs.Inputs["exec"]().(*exec.Exec) ex := inputs.Inputs["exec"]().(*exec.Exec)
config := &parsers.Config{ p, err := parsers.NewParser(&parsers.Config{
MetricName: "exec", MetricName: "exec",
DataFormat: "json", DataFormat: "json",
} })
p, err := parsers.NewParser(config)
assert.NoError(t, err) assert.NoError(t, err)
ex.SetParser(p) ex.SetParser(p)
ex.Command = "/usr/bin/myothercollector --foo=bar" ex.Command = "/usr/bin/myothercollector --foo=bar"

View File

@ -93,11 +93,10 @@ func (r runnerMock) Run(e *Exec, command string, acc telegraf.Accumulator) ([]by
} }
func TestExec(t *testing.T) { func TestExec(t *testing.T) {
config := &parsers.Config{ parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "exec", MetricName: "exec",
} })
parser, _ := parsers.NewParser(config)
e := &Exec{ e := &Exec{
runner: newRunnerMock([]byte(validJson), nil), runner: newRunnerMock([]byte(validJson), nil),
Commands: []string{"testcommand arg1"}, Commands: []string{"testcommand arg1"},
@ -123,11 +122,10 @@ func TestExec(t *testing.T) {
} }
func TestExecMalformed(t *testing.T) { func TestExecMalformed(t *testing.T) {
config := &parsers.Config{ parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "exec", MetricName: "exec",
} })
parser, _ := parsers.NewParser(config)
e := &Exec{ e := &Exec{
runner: newRunnerMock([]byte(malformedJson), nil), runner: newRunnerMock([]byte(malformedJson), nil),
Commands: []string{"badcommand arg1"}, Commands: []string{"badcommand arg1"},
@ -140,11 +138,10 @@ func TestExecMalformed(t *testing.T) {
} }
func TestCommandError(t *testing.T) { func TestCommandError(t *testing.T) {
config := &parsers.Config{ parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "exec", MetricName: "exec",
} })
parser, _ := parsers.NewParser(config)
e := &Exec{ e := &Exec{
runner: newRunnerMock(nil, fmt.Errorf("exit status code 1")), runner: newRunnerMock(nil, fmt.Errorf("exit status code 1")),
Commands: []string{"badcommand"}, Commands: []string{"badcommand"},

View File

@ -26,11 +26,11 @@ func TestHTTPwithJSONFormat(t *testing.T) {
URLs: []string{url}, URLs: []string{url},
} }
metricName := "metricName" metricName := "metricName"
config := &parsers.Config{
p, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "metricName", MetricName: "metricName",
} })
p, _ := parsers.NewParser(config)
plugin.SetParser(p) plugin.SetParser(p)
var acc testutil.Accumulator var acc testutil.Accumulator
@ -68,11 +68,10 @@ func TestHTTPHeaders(t *testing.T) {
Headers: map[string]string{header: headerValue}, Headers: map[string]string{header: headerValue},
} }
config := &parsers.Config{ p, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "metricName", MetricName: "metricName",
} })
p, _ := parsers.NewParser(config)
plugin.SetParser(p) plugin.SetParser(p)
var acc testutil.Accumulator var acc testutil.Accumulator
@ -91,11 +90,10 @@ func TestInvalidStatusCode(t *testing.T) {
} }
metricName := "metricName" metricName := "metricName"
config := &parsers.Config{ p, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: metricName, MetricName: metricName,
} })
p, _ := parsers.NewParser(config)
plugin.SetParser(p) plugin.SetParser(p)
var acc testutil.Accumulator var acc testutil.Accumulator
@ -117,11 +115,10 @@ func TestMethod(t *testing.T) {
Method: "POST", Method: "POST",
} }
config := &parsers.Config{ p, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "metricName", MetricName: "metricName",
} })
p, _ := parsers.NewParser(config)
plugin.SetParser(p) plugin.SetParser(p)
var acc testutil.Accumulator var acc testutil.Accumulator

View File

@ -181,14 +181,12 @@ func (h *HttpJson) gatherServer(
"server": serverURL, "server": serverURL,
} }
config := &parsers.Config{ parser, err := parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: msrmnt_name, MetricName: msrmnt_name,
TagKeys: h.TagKeys, TagKeys: h.TagKeys,
DefaultTags: tags, DefaultTags: tags,
} })
parser, err := parsers.NewParser(config)
if err != nil { if err != nil {
return err return err
} }

View File

@ -125,11 +125,10 @@ func TestRunParserAndGatherJSON(t *testing.T) {
k.acc = &acc k.acc = &acc
defer close(k.done) defer close(k.done)
config := &parsers.Config{ k.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "kafka_json_test", MetricName: "kafka_json_test",
} })
k.parser, _ = parsers.NewParser(config)
go k.receiver() go k.receiver()
in <- saramaMsg(testMsgJSON) in <- saramaMsg(testMsgJSON)
acc.Wait(1) acc.Wait(1)

View File

@ -125,12 +125,10 @@ func TestRunParserAndGatherJSON(t *testing.T) {
k.acc = &acc k.acc = &acc
defer close(k.done) defer close(k.done)
config := &parsers.Config{ k.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "kafka_json_test", MetricName: "kafka_json_test",
} })
k.parser, _ = parsers.NewParser(config)
go k.receiver() go k.receiver()
in <- saramaMsg(testMsgJSON) in <- saramaMsg(testMsgJSON)
acc.Wait(1) acc.Wait(1)

View File

@ -172,12 +172,10 @@ func TestRunParserAndGatherJSON(t *testing.T) {
n.acc = &acc n.acc = &acc
defer close(n.done) defer close(n.done)
config := &parsers.Config{ n.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "nats_json_test", MetricName: "nats_json_test",
} })
n.parser, _ = parsers.NewParser(config)
go n.receiver() go n.receiver()
in <- mqttMsg(testMsgJSON) in <- mqttMsg(testMsgJSON)

View File

@ -108,12 +108,10 @@ func TestRunParserAndGatherJSON(t *testing.T) {
n.acc = &acc n.acc = &acc
defer close(n.done) defer close(n.done)
config := &parsers.Config{ n.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "nats_json_test", MetricName: "nats_json_test",
} })
n.parser, _ = parsers.NewParser(config)
n.wg.Add(1) n.wg.Add(1)
go n.receiver() go n.receiver()
in <- natsMsg(testMsgJSON) in <- natsMsg(testMsgJSON)

View File

@ -300,12 +300,10 @@ func TestRunParserJSONMsg(t *testing.T) {
listener.acc = &acc listener.acc = &acc
defer close(listener.done) defer close(listener.done)
config := &parsers.Config{ listener.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "udp_json_test", MetricName: "udp_json_test",
} })
listener.parser, _ = parsers.NewParser(config)
listener.wg.Add(1) listener.wg.Add(1)
go listener.tcpParser() go listener.tcpParser()

View File

@ -193,12 +193,10 @@ func TestRunParserJSONMsg(t *testing.T) {
listener.acc = &acc listener.acc = &acc
defer close(listener.done) defer close(listener.done)
config := &parsers.Config{ listener.parser, _ = parsers.NewParser(&parsers.Config{
DataFormat: "json", DataFormat: "json",
MetricName: "udp_json_test", MetricName: "udp_json_test",
} })
listener.parser, _ = parsers.NewParser(config)
listener.wg.Add(1) listener.wg.Add(1)
go listener.udpParser() go listener.udpParser()