-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclient_test.go
More file actions
81 lines (77 loc) · 1.7 KB
/
client_test.go
File metadata and controls
81 lines (77 loc) · 1.7 KB
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
73
74
75
76
77
78
79
80
81
package metrics
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBaseTags(t *testing.T) {
tests := []struct {
name string
config *StatterConfig
expected []string
}{
{
name: "Datadog agent with default tags",
config: &StatterConfig{
Agent: DatadogAgent,
EnvName: "prod",
HostName: "host1",
DefaultTags: []interface{}{
"key1", "value1",
"key2", "value2",
},
},
expected: []string{"env:prod", "machine:host1", "key1:value1", "key2:value2"},
},
{
name: "Telegraf agent with default tags",
config: &StatterConfig{
Agent: TelegrafAgent,
EnvName: "dev",
HostName: "host2",
DefaultTags: []interface{}{
"key1", "value1",
"key2", "value2",
},
},
expected: []string{"env", "dev", "machine", "host2", "key1", "value1", "key2", "value2"},
},
{
name: "Datadog agent with no default tags",
config: &StatterConfig{
Agent: DatadogAgent,
EnvName: "staging",
HostName: "host3",
DefaultTags: nil,
},
expected: []string{"env:staging", "machine:host3"},
},
{
name: "Telegraf agent with no default tags",
config: &StatterConfig{
Agent: TelegrafAgent,
EnvName: "test",
HostName: "host4",
DefaultTags: nil,
},
expected: []string{"env", "test", "machine", "host4"},
},
{
name: "Empty config",
config: &StatterConfig{
Agent: DatadogAgent,
DefaultTags: nil,
},
expected: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Cleanup(func() {
config = nil
})
config = tt.config
result := tt.config.BaseTags()
assert.ElementsMatch(t, tt.expected, result)
})
}
}