2015-07-07 09:20:11 +08:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
|
|
package mongodb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2016-01-21 02:57:35 +08:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-07-07 09:20:11 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetDefaultTags(t *testing.T) {
|
|
|
|
|
var tagTests = []struct {
|
|
|
|
|
in string
|
|
|
|
|
out string
|
|
|
|
|
}{
|
2015-07-10 04:06:18 +08:00
|
|
|
{"hostname", server.Url.Host},
|
2015-07-07 09:20:11 +08:00
|
|
|
}
|
|
|
|
|
defaultTags := server.getDefaultTags()
|
|
|
|
|
for _, tt := range tagTests {
|
|
|
|
|
if defaultTags[tt.in] != tt.out {
|
|
|
|
|
t.Errorf("expected %q, got %q", tt.out, defaultTags[tt.in])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAddDefaultStats(t *testing.T) {
|
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
2016-07-19 19:47:12 +08:00
|
|
|
err := server.gatherData(&acc, false)
|
2015-07-07 09:20:11 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// need to call this twice so it can perform the diff
|
2016-07-19 19:47:12 +08:00
|
|
|
err = server.gatherData(&acc, false)
|
2015-07-07 09:20:11 +08:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
2018-10-20 04:32:54 +08:00
|
|
|
for key := range DefaultStats {
|
2017-05-17 06:25:30 +08:00
|
|
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
2015-07-07 09:20:11 +08:00
|
|
|
}
|
|
|
|
|
}
|