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.")
ex := inputs.Inputs["exec"]().(*exec.Exec)
config := &parsers.Config{
p, err := parsers.NewParser(&parsers.Config{
MetricName: "exec",
DataFormat: "json",
}
p, err := parsers.NewParser(config)
})
assert.NoError(t, err)
ex.SetParser(p)
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) {
config := &parsers.Config{
parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json",
MetricName: "exec",
}
parser, _ := parsers.NewParser(config)
})
e := &Exec{
runner: newRunnerMock([]byte(validJson), nil),
Commands: []string{"testcommand arg1"},
@ -123,11 +122,10 @@ func TestExec(t *testing.T) {
}
func TestExecMalformed(t *testing.T) {
config := &parsers.Config{
parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json",
MetricName: "exec",
}
parser, _ := parsers.NewParser(config)
})
e := &Exec{
runner: newRunnerMock([]byte(malformedJson), nil),
Commands: []string{"badcommand arg1"},
@ -140,11 +138,10 @@ func TestExecMalformed(t *testing.T) {
}
func TestCommandError(t *testing.T) {
config := &parsers.Config{
parser, _ := parsers.NewParser(&parsers.Config{
DataFormat: "json",
MetricName: "exec",
}
parser, _ := parsers.NewParser(config)
})
e := &Exec{
runner: newRunnerMock(nil, fmt.Errorf("exit status code 1")),
Commands: []string{"badcommand"},

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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