forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries_test.go
72 lines (65 loc) · 2.29 KB
/
queries_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package sqlserverreceiver
import (
"os"
"path"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestQueryContents(t *testing.T) {
queryTests := []struct {
name string
instanceName string
getQuery func(string) string
expectedQueryValFilename string
}{
{
name: "Test database IO query without instance name",
instanceName: "",
getQuery: getSQLServerDatabaseIOQuery,
expectedQueryValFilename: "databaseIOQueryWithoutInstanceName.txt",
},
{
name: "Test database IO query with instance name",
instanceName: "instanceName",
getQuery: getSQLServerDatabaseIOQuery,
expectedQueryValFilename: "databaseIOQueryWithInstanceName.txt",
},
{
name: "Test perf counter query without instance name",
instanceName: "",
getQuery: getSQLServerPerformanceCounterQuery,
expectedQueryValFilename: "perfCounterQueryWithoutInstanceName.txt",
},
{
name: "Test perf counter query with instance name",
instanceName: "instanceName",
getQuery: getSQLServerPerformanceCounterQuery,
expectedQueryValFilename: "perfCounterQueryWithInstanceName.txt",
},
{
name: "Test properties query without instance name",
instanceName: "",
getQuery: getSQLServerPropertiesQuery,
expectedQueryValFilename: "propertyQueryWithoutInstanceName.txt",
},
{
name: "Test properties query with instance name",
instanceName: "instanceName",
getQuery: getSQLServerPropertiesQuery,
expectedQueryValFilename: "propertyQueryWithInstanceName.txt",
},
}
for _, tt := range queryTests {
t.Run(tt.name, func(t *testing.T) {
expectedBytes, err := os.ReadFile(path.Join("./testdata", tt.expectedQueryValFilename))
require.NoError(t, err)
// Replace all will fix newlines when testing on Windows
expected := strings.ReplaceAll(string(expectedBytes), "\r\n", "\n")
actual := tt.getQuery(tt.instanceName)
require.Equal(t, expected, actual)
})
}
}