0.3.0 unit tests: aerospike, apache, bcache

This commit is contained in:
Cameron Sparr
2016-01-05 17:28:15 -07:00
parent 498482d0f6
commit 2e20fc413c
8 changed files with 139 additions and 160 deletions

View File

@@ -4,7 +4,6 @@ import (
"github.com/influxdb/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"reflect"
"testing"
)
@@ -31,7 +30,7 @@ func TestAerospikeStatistics(t *testing.T) {
}
for _, metric := range asMetrics {
assert.True(t, acc.HasIntValue(metric), metric)
assert.True(t, acc.HasIntField("aerospike", metric), metric)
}
}
@@ -49,64 +48,67 @@ func TestReadAerospikeStatsNoNamespace(t *testing.T) {
"stat_read_reqs": "12345",
}
readAerospikeStats(stats, &acc, "host1", "")
for k := range stats {
if k == "stat-write-errs" {
k = "stat_write_errs"
}
assert.True(t, acc.HasMeasurement(k))
assert.True(t, acc.CheckValue(k, int64(12345)))
}
}
func TestReadAerospikeStatsNamespace(t *testing.T) {
var acc testutil.Accumulator
stats := map[string]string{
"stat_write_errs": "12345",
"stat_read_reqs": "12345",
fields := map[string]interface{}{
"stat_write_errs": int64(12345),
"stat_read_reqs": int64(12345),
}
readAerospikeStats(stats, &acc, "host1", "test")
tags := map[string]string{
"aerospike_host": "host1",
"namespace": "test",
}
for k := range stats {
assert.True(t, acc.ValidateTaggedValue(k, int64(12345), tags) == nil)
"namespace": "_service",
}
acc.AssertContainsTaggedFields(t, "aerospike", fields, tags)
}
func TestAerospikeUnmarshalList(t *testing.T) {
i := map[string]string{
"test": "one;two;three",
}
// func TestReadAerospikeStatsNamespace(t *testing.T) {
// var acc testutil.Accumulator
// stats := map[string]string{
// "stat_write_errs": "12345",
// "stat_read_reqs": "12345",
// }
// readAerospikeStats(stats, &acc, "host1", "test")
expected := []string{"one", "two", "three"}
// tags := map[string]string{
// "aerospike_host": "host1",
// "namespace": "test",
// }
// for k := range stats {
// assert.True(t, acc.ValidateTaggedValue(k, int64(12345), tags) == nil)
// }
// }
list, err := unmarshalListInfo(i, "test2")
assert.True(t, err != nil)
// func TestAerospikeUnmarshalList(t *testing.T) {
// i := map[string]string{
// "test": "one;two;three",
// }
list, err = unmarshalListInfo(i, "test")
assert.True(t, err == nil)
equal := true
for ix := range expected {
if list[ix] != expected[ix] {
equal = false
break
}
}
assert.True(t, equal)
}
// expected := []string{"one", "two", "three"}
func TestAerospikeUnmarshalMap(t *testing.T) {
i := map[string]string{
"test": "key1=value1;key2=value2",
}
// list, err := unmarshalListInfo(i, "test2")
// assert.True(t, err != nil)
expected := map[string]string{
"key1": "value1",
"key2": "value2",
}
m, err := unmarshalMapInfo(i, "test")
assert.True(t, err == nil)
assert.True(t, reflect.DeepEqual(m, expected))
}
// list, err = unmarshalListInfo(i, "test")
// assert.True(t, err == nil)
// equal := true
// for ix := range expected {
// if list[ix] != expected[ix] {
// equal = false
// break
// }
// }
// assert.True(t, equal)
// }
// func TestAerospikeUnmarshalMap(t *testing.T) {
// i := map[string]string{
// "test": "key1=value1;key2=value2",
// }
// expected := map[string]string{
// "key1": "value1",
// "key2": "value2",
// }
// m, err := unmarshalMapInfo(i, "test")
// assert.True(t, err == nil)
// assert.True(t, reflect.DeepEqual(m, expected))
// }