dns query: Don't use mjasion.pl for unit tests, check errs

This commit is contained in:
Cameron Sparr 2016-02-23 11:10:28 -07:00
parent 3e8f96a463
commit 83c27cc7b1
2 changed files with 19 additions and 10 deletions

View File

@ -8,6 +8,7 @@
### Bugfixes ### Bugfixes
- [#701](https://github.com/influxdata/telegraf/pull/701): output write count shouldnt print in quiet mode. - [#701](https://github.com/influxdata/telegraf/pull/701): output write count shouldnt print in quiet mode.
- [#746](https://github.com/influxdata/telegraf/pull/746): httpjson plugin: Fix HTTP GET parameters.
## v0.10.3 [2016-02-18] ## v0.10.3 [2016-02-18]

View File

@ -9,7 +9,7 @@ import (
) )
var servers = []string{"8.8.8.8"} var servers = []string{"8.8.8.8"}
var domains = []string{"mjasion.pl"} var domains = []string{"google.com"}
func TestGathering(t *testing.T) { func TestGathering(t *testing.T) {
var dnsConfig = DnsQuery{ var dnsConfig = DnsQuery{
@ -18,8 +18,10 @@ func TestGathering(t *testing.T) {
} }
var acc testutil.Accumulator var acc testutil.Accumulator
dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
metric, _ := acc.Get("dns_query") assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
assert.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)
@ -33,8 +35,10 @@ func TestGatheringMxRecord(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
dnsConfig.RecordType = "MX" dnsConfig.RecordType = "MX"
dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
metric, _ := acc.Get("dns_query") assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
assert.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)
@ -54,8 +58,10 @@ func TestGatheringRootDomain(t *testing.T) {
} }
fields := map[string]interface{}{} fields := map[string]interface{}{}
dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
metric, _ := acc.Get("dns_query") assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
assert.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
@ -70,13 +76,15 @@ func TestMetricContainsServerAndDomainAndRecordTypeTags(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
tags := map[string]string{ tags := map[string]string{
"server": "8.8.8.8", "server": "8.8.8.8",
"domain": "mjasion.pl", "domain": "google.com",
"record_type": "NS", "record_type": "NS",
} }
fields := map[string]interface{}{} fields := map[string]interface{}{}
dnsConfig.Gather(&acc) err := dnsConfig.Gather(&acc)
metric, _ := acc.Get("dns_query") assert.NoError(t, err)
metric, ok := acc.Get("dns_query")
assert.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