dns_query unit tests, require that field exists

This commit is contained in:
Cameron Sparr 2016-03-03 15:44:16 +00:00 committed by Michele Fadda
parent 4b5dac0cba
commit 300a00b95d
1 changed files with 10 additions and 7 deletions

View File

@ -1,11 +1,14 @@
package dns_query package dns_query
import ( import (
"github.com/influxdata/telegraf/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"testing" "testing"
"time" "time"
"github.com/influxdata/telegraf/testutil"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
var servers = []string{"8.8.8.8"} var servers = []string{"8.8.8.8"}
@ -21,7 +24,7 @@ func TestGathering(t *testing.T) {
err := dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
assert.NoError(t, err) assert.NoError(t, err)
metric, ok := acc.Get("dns_query") metric, ok := acc.Get("dns_query")
assert.True(t, ok) require.True(t, ok)
queryTime, _ := metric.Fields["query_time_ms"].(float64) queryTime, _ := metric.Fields["query_time_ms"].(float64)
assert.NotEqual(t, 0, queryTime) assert.NotEqual(t, 0, queryTime)
@ -38,7 +41,7 @@ func TestGatheringMxRecord(t *testing.T) {
err := dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
assert.NoError(t, err) assert.NoError(t, err)
metric, ok := acc.Get("dns_query") metric, ok := acc.Get("dns_query")
assert.True(t, ok) require.True(t, ok)
queryTime, _ := metric.Fields["query_time_ms"].(float64) queryTime, _ := metric.Fields["query_time_ms"].(float64)
assert.NotEqual(t, 0, queryTime) assert.NotEqual(t, 0, queryTime)
@ -61,7 +64,7 @@ func TestGatheringRootDomain(t *testing.T) {
err := dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
assert.NoError(t, err) assert.NoError(t, err)
metric, ok := acc.Get("dns_query") metric, ok := acc.Get("dns_query")
assert.True(t, ok) require.True(t, ok)
queryTime, _ := metric.Fields["query_time_ms"].(float64) queryTime, _ := metric.Fields["query_time_ms"].(float64)
fields["query_time_ms"] = queryTime fields["query_time_ms"] = queryTime
@ -84,7 +87,7 @@ func TestMetricContainsServerAndDomainAndRecordTypeTags(t *testing.T) {
err := dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
assert.NoError(t, err) assert.NoError(t, err)
metric, ok := acc.Get("dns_query") metric, ok := acc.Get("dns_query")
assert.True(t, ok) require.True(t, ok)
queryTime, _ := metric.Fields["query_time_ms"].(float64) queryTime, _ := metric.Fields["query_time_ms"].(float64)
fields["query_time_ms"] = queryTime fields["query_time_ms"] = queryTime