0.3.0 unit tests: mailchimp, memcached, mongodb
This commit is contained in:
parent
9ada89d51a
commit
6a4bf9fcff
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/influxdb/telegraf/testutil"
|
"github.com/influxdb/telegraf/testutil"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,67 +41,38 @@ func TestMailChimpGatherReports(t *testing.T) {
|
||||||
tags["id"] = "42694e9e57"
|
tags["id"] = "42694e9e57"
|
||||||
tags["campaign_title"] = "Freddie's Jokes Vol. 1"
|
tags["campaign_title"] = "Freddie's Jokes Vol. 1"
|
||||||
|
|
||||||
testInts := []struct {
|
fields := map[string]interface{}{
|
||||||
measurement string
|
"emails_sent": int(200),
|
||||||
value int
|
"abuse_reports": int(0),
|
||||||
}{
|
"unsubscribed": int(2),
|
||||||
{"emails_sent", 200},
|
"hard_bounces": int(0),
|
||||||
{"abuse_reports", 0},
|
"soft_bounces": int(2),
|
||||||
{"unsubscribed", 2},
|
"syntax_errors": int(0),
|
||||||
{"hard_bounces", 0},
|
"forwards_count": int(0),
|
||||||
{"soft_bounces", 2},
|
"forwards_opens": int(0),
|
||||||
{"syntax_errors", 0},
|
"opens_total": int(186),
|
||||||
{"forwards_count", 0},
|
"unique_opens": int(100),
|
||||||
{"forwards_opens", 0},
|
"clicks_total": int(42),
|
||||||
{"opens_total", 186},
|
"unique_clicks": int(400),
|
||||||
{"unique_opens", 100},
|
"unique_subscriber_clicks": int(42),
|
||||||
{"clicks_total", 42},
|
"facebook_recipient_likes": int(5),
|
||||||
{"unique_clicks", 400},
|
"facebook_unique_likes": int(8),
|
||||||
{"unique_subscriber_clicks", 42},
|
"facebook_likes": int(42),
|
||||||
{"facebook_recipient_likes", 5},
|
"open_rate": float64(42),
|
||||||
{"facebook_unique_likes", 8},
|
"click_rate": float64(42),
|
||||||
{"facebook_likes", 42},
|
"industry_open_rate": float64(0.17076777144396),
|
||||||
}
|
"industry_click_rate": float64(0.027431311866951),
|
||||||
for _, test := range testInts {
|
"industry_bounce_rate": float64(0.0063767751251474),
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
"industry_unopen_rate": float64(0.82285545343089),
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
"industry_unsub_rate": float64(0.001436957032815),
|
||||||
test.measurement, test.value, tags))
|
"industry_abuse_rate": float64(0.00021111996110887),
|
||||||
}
|
"list_stats_sub_rate": float64(10),
|
||||||
|
"list_stats_unsub_rate": float64(20),
|
||||||
testFloats := []struct {
|
"list_stats_open_rate": float64(42),
|
||||||
measurement string
|
"list_stats_click_rate": float64(42),
|
||||||
value float64
|
"industry_type": "Social Networks and Online Communities",
|
||||||
}{
|
|
||||||
{"open_rate", 42},
|
|
||||||
{"click_rate", 42},
|
|
||||||
{"industry_open_rate", 0.17076777144396},
|
|
||||||
{"industry_click_rate", 0.027431311866951},
|
|
||||||
{"industry_bounce_rate", 0.0063767751251474},
|
|
||||||
{"industry_unopen_rate", 0.82285545343089},
|
|
||||||
{"industry_unsub_rate", 0.001436957032815},
|
|
||||||
{"industry_abuse_rate", 0.00021111996110887},
|
|
||||||
{"list_stats_sub_rate", 10},
|
|
||||||
{"list_stats_unsub_rate", 20},
|
|
||||||
{"list_stats_open_rate", 42},
|
|
||||||
{"list_stats_click_rate", 42},
|
|
||||||
}
|
|
||||||
for _, test := range testFloats {
|
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
|
||||||
test.measurement, test.value, tags))
|
|
||||||
}
|
|
||||||
|
|
||||||
testStrings := []struct {
|
|
||||||
measurement string
|
|
||||||
value string
|
|
||||||
}{
|
|
||||||
{"industry_type", "Social Networks and Online Communities"},
|
|
||||||
}
|
|
||||||
for _, test := range testStrings {
|
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
|
||||||
test.measurement, test.value, tags))
|
|
||||||
}
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "mailchimp", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMailChimpGatherReport(t *testing.T) {
|
func TestMailChimpGatherReport(t *testing.T) {
|
||||||
|
@ -135,67 +105,39 @@ func TestMailChimpGatherReport(t *testing.T) {
|
||||||
tags["id"] = "42694e9e57"
|
tags["id"] = "42694e9e57"
|
||||||
tags["campaign_title"] = "Freddie's Jokes Vol. 1"
|
tags["campaign_title"] = "Freddie's Jokes Vol. 1"
|
||||||
|
|
||||||
testInts := []struct {
|
fields := map[string]interface{}{
|
||||||
measurement string
|
"emails_sent": int(200),
|
||||||
value int
|
"abuse_reports": int(0),
|
||||||
}{
|
"unsubscribed": int(2),
|
||||||
{"emails_sent", 200},
|
"hard_bounces": int(0),
|
||||||
{"abuse_reports", 0},
|
"soft_bounces": int(2),
|
||||||
{"unsubscribed", 2},
|
"syntax_errors": int(0),
|
||||||
{"hard_bounces", 0},
|
"forwards_count": int(0),
|
||||||
{"soft_bounces", 2},
|
"forwards_opens": int(0),
|
||||||
{"syntax_errors", 0},
|
"opens_total": int(186),
|
||||||
{"forwards_count", 0},
|
"unique_opens": int(100),
|
||||||
{"forwards_opens", 0},
|
"clicks_total": int(42),
|
||||||
{"opens_total", 186},
|
"unique_clicks": int(400),
|
||||||
{"unique_opens", 100},
|
"unique_subscriber_clicks": int(42),
|
||||||
{"clicks_total", 42},
|
"facebook_recipient_likes": int(5),
|
||||||
{"unique_clicks", 400},
|
"facebook_unique_likes": int(8),
|
||||||
{"unique_subscriber_clicks", 42},
|
"facebook_likes": int(42),
|
||||||
{"facebook_recipient_likes", 5},
|
"open_rate": float64(42),
|
||||||
{"facebook_unique_likes", 8},
|
"click_rate": float64(42),
|
||||||
{"facebook_likes", 42},
|
"industry_open_rate": float64(0.17076777144396),
|
||||||
}
|
"industry_click_rate": float64(0.027431311866951),
|
||||||
for _, test := range testInts {
|
"industry_bounce_rate": float64(0.0063767751251474),
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
"industry_unopen_rate": float64(0.82285545343089),
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
"industry_unsub_rate": float64(0.001436957032815),
|
||||||
test.measurement, test.value, tags))
|
"industry_abuse_rate": float64(0.00021111996110887),
|
||||||
|
"list_stats_sub_rate": float64(10),
|
||||||
|
"list_stats_unsub_rate": float64(20),
|
||||||
|
"list_stats_open_rate": float64(42),
|
||||||
|
"list_stats_click_rate": float64(42),
|
||||||
|
"industry_type": "Social Networks and Online Communities",
|
||||||
}
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "mailchimp", fields, tags)
|
||||||
|
|
||||||
testFloats := []struct {
|
|
||||||
measurement string
|
|
||||||
value float64
|
|
||||||
}{
|
|
||||||
{"open_rate", 42},
|
|
||||||
{"click_rate", 42},
|
|
||||||
{"industry_open_rate", 0.17076777144396},
|
|
||||||
{"industry_click_rate", 0.027431311866951},
|
|
||||||
{"industry_bounce_rate", 0.0063767751251474},
|
|
||||||
{"industry_unopen_rate", 0.82285545343089},
|
|
||||||
{"industry_unsub_rate", 0.001436957032815},
|
|
||||||
{"industry_abuse_rate", 0.00021111996110887},
|
|
||||||
{"list_stats_sub_rate", 10},
|
|
||||||
{"list_stats_unsub_rate", 20},
|
|
||||||
{"list_stats_open_rate", 42},
|
|
||||||
{"list_stats_click_rate", 42},
|
|
||||||
}
|
|
||||||
for _, test := range testFloats {
|
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
|
||||||
test.measurement, test.value, tags))
|
|
||||||
}
|
|
||||||
|
|
||||||
testStrings := []struct {
|
|
||||||
measurement string
|
|
||||||
value string
|
|
||||||
}{
|
|
||||||
{"industry_type", "Social Networks and Online Communities"},
|
|
||||||
}
|
|
||||||
for _, test := range testStrings {
|
|
||||||
assert.True(t, acc.CheckTaggedValue(test.measurement, test.value, tags),
|
|
||||||
fmt.Sprintf("Measurement: %v, value: %v, tags: %v not found",
|
|
||||||
test.measurement, test.value, tags))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMailChimpGatherError(t *testing.T) {
|
func TestMailChimpGatherError(t *testing.T) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ func (m *Memcached) gatherServer(
|
||||||
for _, key := range sendMetrics {
|
for _, key := range sendMetrics {
|
||||||
if value, ok := values[key]; ok {
|
if value, ok := values[key]; ok {
|
||||||
// Mostly it is the number
|
// Mostly it is the number
|
||||||
if iValue, errParse := strconv.ParseInt(value, 10, 64); errParse != nil {
|
if iValue, errParse := strconv.ParseInt(value, 10, 64); errParse == nil {
|
||||||
fields[key] = iValue
|
fields[key] = iValue
|
||||||
} else {
|
} else {
|
||||||
fields[key] = value
|
fields[key] = value
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
||||||
"bytes_read", "bytes_written", "threads", "conn_yields"}
|
"bytes_read", "bytes_written", "threads", "conn_yields"}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntValue(metric), metric)
|
assert.True(t, acc.HasIntField("memcached", metric), metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/influxdb/telegraf/testutil"
|
"github.com/influxdb/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var tags = make(map[string]string)
|
var tags = make(map[string]string)
|
||||||
|
@ -37,10 +36,11 @@ func TestAddNonReplStats(t *testing.T) {
|
||||||
)
|
)
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
d.AddDefaultStats(&acc)
|
d.AddDefaultStats()
|
||||||
|
d.flush(&acc)
|
||||||
|
|
||||||
for key, _ := range DefaultStats {
|
for key, _ := range DefaultStats {
|
||||||
assert.True(t, acc.HasIntValue(key))
|
assert.True(t, acc.HasIntField("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +57,11 @@ func TestAddReplStats(t *testing.T) {
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
d.AddDefaultStats(&acc)
|
d.AddDefaultStats()
|
||||||
|
d.flush(&acc)
|
||||||
|
|
||||||
for key, _ := range MmapStats {
|
for key, _ := range MmapStats {
|
||||||
assert.True(t, acc.HasIntValue(key))
|
assert.True(t, acc.HasIntField("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +77,11 @@ func TestAddWiredTigerStats(t *testing.T) {
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
d.AddDefaultStats(&acc)
|
d.AddDefaultStats()
|
||||||
|
d.flush(&acc)
|
||||||
|
|
||||||
for key, _ := range WiredTigerStats {
|
for key, _ := range WiredTigerStats {
|
||||||
assert.True(t, acc.HasFloatValue(key))
|
assert.True(t, acc.HasFloatField("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,17 +97,37 @@ func TestStateTag(t *testing.T) {
|
||||||
tags,
|
tags,
|
||||||
)
|
)
|
||||||
|
|
||||||
stats := []string{"inserts_per_sec", "queries_per_sec"}
|
|
||||||
|
|
||||||
stateTags := make(map[string]string)
|
stateTags := make(map[string]string)
|
||||||
stateTags["state"] = "PRI"
|
stateTags["state"] = "PRI"
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
d.AddDefaultStats(&acc)
|
d.AddDefaultStats()
|
||||||
|
d.flush(&acc)
|
||||||
for _, key := range stats {
|
fields := map[string]interface{}{
|
||||||
err := acc.ValidateTaggedValue(key, int64(0), stateTags)
|
"active_reads": int64(0),
|
||||||
require.NoError(t, err)
|
"active_writes": int64(0),
|
||||||
|
"commands_per_sec": int64(0),
|
||||||
|
"deletes_per_sec": int64(0),
|
||||||
|
"flushes_per_sec": int64(0),
|
||||||
|
"getmores_per_sec": int64(0),
|
||||||
|
"inserts_per_sec": int64(0),
|
||||||
|
"member_status": "PRI",
|
||||||
|
"net_in_bytes": int64(0),
|
||||||
|
"net_out_bytes": int64(0),
|
||||||
|
"open_connections": int64(0),
|
||||||
|
"queries_per_sec": int64(0),
|
||||||
|
"queued_reads": int64(0),
|
||||||
|
"queued_writes": int64(0),
|
||||||
|
"repl_commands_per_sec": int64(0),
|
||||||
|
"repl_deletes_per_sec": int64(0),
|
||||||
|
"repl_getmores_per_sec": int64(0),
|
||||||
|
"repl_inserts_per_sec": int64(0),
|
||||||
|
"repl_queries_per_sec": int64(0),
|
||||||
|
"repl_updates_per_sec": int64(0),
|
||||||
|
"resident_megabytes": int64(0),
|
||||||
|
"updates_per_sec": int64(0),
|
||||||
|
"vsize_megabytes": int64(0),
|
||||||
}
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "mongodb", fields, stateTags)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue