telegraf/plugins/inputs/mongodb/mongodb_server_test.go

43 lines
940 B
Go
Raw Normal View History

//go:build integration
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
}{
2021-07-23 04:50:23 +08:00
{"hostname", server.hostname},
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
2021-07-23 04:50:23 +08:00
err := server.gatherData(&acc, false, true, true, true, []string{"local"})
2015-07-07 09:20:11 +08:00
require.NoError(t, err)
// need to call this twice so it can perform the diff
2021-07-23 04:50:23 +08:00
err = server.gatherData(&acc, false, true, true, true, []string{"local"})
2015-07-07 09:20:11 +08:00
require.NoError(t, err)
for key := range defaultStats {
assert.True(t, acc.HasInt64Field("mongodb", key))
2015-07-07 09:20:11 +08:00
}
}