forked from aws/amazon-cloudwatch-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory_test.go
102 lines (92 loc) · 2.03 KB
/
factory_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package awsebsnvmereceiver
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
)
func TestArrayToSet(t *testing.T) {
testCases := []struct {
name string
input []string
expected map[string]struct{}
}{
{
name: "empty array",
input: []string{},
expected: map[string]struct{}{},
},
{
name: "single item",
input: []string{"nvme0n1"},
expected: map[string]struct{}{
"nvme0n1": {},
},
},
{
name: "multiple items",
input: []string{"nvme0n1", "nvme1n1", "nvme2n1"},
expected: map[string]struct{}{
"nvme0n1": {},
"nvme1n1": {},
"nvme2n1": {},
},
},
{
name: "duplicate items",
input: []string{"nvme0n1", "nvme0n1", "nvme1n1"},
expected: map[string]struct{}{
"nvme0n1": {},
"nvme1n1": {},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := arrayToSet(tc.input)
assert.Equal(t, tc.expected, result)
})
}
}
func TestCreateDefaultConfig(t *testing.T) {
config := createDefaultConfig().(*Config)
assert.NotNil(t, config)
assert.Empty(t, config.Resources)
}
func TestCreateMetricsReceiver(t *testing.T) {
testCases := []struct {
name string
resources []string
}{
{
name: "no resources",
resources: []string{},
},
{
name: "with resources",
resources: []string{"nvme0n1", "nvme1n1"},
},
{
name: "with wildcard",
resources: []string{"*"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Resources = tc.resources
receiver, err := createMetricsReceiver(
context.Background(),
receivertest.NewNopSettings(),
cfg,
consumertest.NewNop(),
)
require.NoError(t, err)
require.NotNil(t, receiver)
})
}
}