From 925c59576070d45687e9e5d694ecc1ebf553809d Mon Sep 17 00:00:00 2001 From: Margarita Bliznikova Date: Mon, 5 Mar 2018 21:10:31 -0800 Subject: [PATCH] Add host to ping timeout log message --- plugins/inputs/ping/ping_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index ca50092a9bf17..bc1cb310414c6 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -268,3 +268,27 @@ 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) + } +}