From 6d2594df28d62b2b043da4d5889d3f0d248fb99f Mon Sep 17 00:00:00 2001 From: Margarita Bliznikova Date: Mon, 5 Mar 2018 21:10:31 -0800 Subject: [PATCH] Add unit test for ping command timeout --- plugins/inputs/ping/ping_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index ca50092a9bf17..32f8b87d9fd76 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -268,3 +268,26 @@ func TestFatalPingGather(t *testing.T) { assert.False(t, acc.HasMeasurement("maximum_response_ms"), "Fatal ping should not have packet measurements") } + +func TestErrorWithHostNamePingGather(t *testing.T) { + params := []struct { + out string + error error + }{ + {"", errors.New("Host www.amazon.com: So very bad")}, + {"so bad", errors.New("Host www.amazon.com: so bad, So very bad")}, + } + + for _, param := range params { + var acc testutil.Accumulator + p := Ping{ + Urls: []string{"www.amazon.com"}, + pingHost: func(timeout float64, args ...string) (string, error) { + return param.out, errors.New("So very bad") + }, + } + acc.GatherError(p.Gather) + assert.True(t, len(acc.Errors) > 0) + assert.Contains(t, acc.Errors, param.error) + } +}