-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathhost_identifier_test.go
More file actions
64 lines (58 loc) · 1.38 KB
/
host_identifier_test.go
File metadata and controls
64 lines (58 loc) · 1.38 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
package helper
import (
"testing"
"github.com/observiq/stanza/entry"
"github.com/stretchr/testify/require"
)
func MockHostIdentifierConfig(includeIP, includeHostname bool, ip, hostname string) HostIdentifierConfig {
return HostIdentifierConfig{
IncludeIP: includeIP,
IncludeHostname: includeHostname,
getIP: func() (string, error) { return ip, nil },
getHostname: func() (string, error) { return hostname, nil },
}
}
func TestHostLabeler(t *testing.T) {
cases := []struct {
name string
config HostIdentifierConfig
expectedResource map[string]string
}{
{
"HostnameAndIP",
MockHostIdentifierConfig(true, true, "ip", "hostname"),
map[string]string{
"host.name": "hostname",
"host.ip": "ip",
},
},
{
"HostnameNoIP",
MockHostIdentifierConfig(false, true, "ip", "hostname"),
map[string]string{
"host.name": "hostname",
},
},
{
"IPNoHostname",
MockHostIdentifierConfig(true, false, "ip", "hostname"),
map[string]string{
"host.ip": "ip",
},
},
{
"NoHostnameNoIP",
MockHostIdentifierConfig(false, false, "", "test"),
nil,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
identifier, err := tc.config.Build()
require.NoError(t, err)
e := entry.New()
identifier.Identify(e)
require.Equal(t, tc.expectedResource, e.Resource)
})
}
}