Skip to content

Commit

Permalink
dns_query unit tests, require that field exists
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc authored and geodimm committed Mar 10, 2016
1 parent 7887b10 commit 97a3261
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions plugins/inputs/dns_query/dns_query_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package dns_query

import (
"testing"
"time"

"github.com/influxdata/telegraf/testutil"

"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/stretchr/testify/require"
)

var servers = []string{"8.8.8.8"}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 97a3261

Please sign in to comment.