Skip to content

Commit

Permalink
Add unit test for ping command timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mbliznikova committed Mar 6, 2018
1 parent 74bf995 commit 6d2594d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions plugins/inputs/ping/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 6d2594d

Please sign in to comment.