From 300a00b95d7e7f73a097ad1729203e614c94c1f9 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 3 Mar 2016 15:44:16 +0000 Subject: [PATCH] dns_query unit tests, require that field exists --- plugins/inputs/dns_query/dns_query_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/dns_query/dns_query_test.go b/plugins/inputs/dns_query/dns_query_test.go index 076db5fab..d7d267a59 100644 --- a/plugins/inputs/dns_query/dns_query_test.go +++ b/plugins/inputs/dns_query/dns_query_test.go @@ -1,11 +1,14 @@ package dns_query import ( - "github.com/influxdata/telegraf/testutil" - "github.com/miekg/dns" - "github.com/stretchr/testify/assert" "testing" "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"} @@ -21,7 +24,7 @@ func TestGathering(t *testing.T) { err := dnsConfig.Gather(&acc) assert.NoError(t, err) metric, ok := acc.Get("dns_query") - assert.True(t, ok) + require.True(t, ok) queryTime, _ := metric.Fields["query_time_ms"].(float64) assert.NotEqual(t, 0, queryTime) @@ -38,7 +41,7 @@ func TestGatheringMxRecord(t *testing.T) { err := dnsConfig.Gather(&acc) assert.NoError(t, err) metric, ok := acc.Get("dns_query") - assert.True(t, ok) + require.True(t, ok) queryTime, _ := metric.Fields["query_time_ms"].(float64) assert.NotEqual(t, 0, queryTime) @@ -61,7 +64,7 @@ func TestGatheringRootDomain(t *testing.T) { err := dnsConfig.Gather(&acc) assert.NoError(t, err) metric, ok := acc.Get("dns_query") - assert.True(t, ok) + require.True(t, ok) queryTime, _ := metric.Fields["query_time_ms"].(float64) fields["query_time_ms"] = queryTime @@ -84,7 +87,7 @@ func TestMetricContainsServerAndDomainAndRecordTypeTags(t *testing.T) { err := dnsConfig.Gather(&acc) assert.NoError(t, err) metric, ok := acc.Get("dns_query") - assert.True(t, ok) + require.True(t, ok) queryTime, _ := metric.Fields["query_time_ms"].(float64) fields["query_time_ms"] = queryTime