2021-08-24 04:37:44 +08:00
|
|
|
//go:build integration
|
2015-07-07 09:20:11 +08:00
|
|
|
// +build integration
|
|
|
|
|
|
|
|
|
|
package mongodb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-11-02 22:49:26 +08:00
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-07-07 09:20:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2021-03-17 04:54:57 +08:00
|
|
|
for key := range defaultStats {
|
2021-11-02 22:49:26 +08:00
|
|
|
require.True(t, acc.HasInt64Field("mongodb", key))
|
2015-07-07 09:20:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-08-27 04:32:48 +08:00
|
|
|
|
|
|
|
|
func TestPoolStatsVersionCompatibility(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
version string
|
|
|
|
|
expectedCommand string
|
|
|
|
|
err bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "mongodb v3",
|
|
|
|
|
version: "3.0.0",
|
|
|
|
|
expectedCommand: "shardConnPoolStats",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "mongodb v4",
|
|
|
|
|
version: "4.0.0",
|
|
|
|
|
expectedCommand: "shardConnPoolStats",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "mongodb v5",
|
|
|
|
|
version: "5.0.0",
|
|
|
|
|
expectedCommand: "connPoolStats",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "invalid version",
|
|
|
|
|
version: "v4",
|
|
|
|
|
err: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
command, err := poolStatsCommand(test.version)
|
|
|
|
|
require.Equal(t, test.expectedCommand, command)
|
|
|
|
|
if test.err {
|
|
|
|
|
require.Error(t, err)
|
|
|
|
|
} else {
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|