-
Notifications
You must be signed in to change notification settings - Fork 43
/
config_test.go
57 lines (49 loc) · 1.21 KB
/
config_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
package opamp
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseConfigInvalidPath(t *testing.T) {
_, err := ParseAgentManagerConfig("./testdata/collector.yaml")
if err == nil {
t.Errorf("expected error")
}
}
func TestParseConfigInvalidYaml(t *testing.T) {
cfg, err := ParseAgentManagerConfig("./testdata/invalid.yaml")
if err == nil {
t.Errorf("expected error")
}
if cfg != nil {
t.Errorf("expected nil config but got %v", cfg)
}
}
func TestParseConfig(t *testing.T) {
cfg, err := ParseAgentManagerConfig("./testdata/manager-config.yaml")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if cfg == nil {
t.Errorf("expected config")
}
}
func TestParseConfigAddsID(t *testing.T) {
// make a copy of the file
func() {
copy("./testdata/agent-id.yaml", "./testdata/agent-id-copy.yaml")
}()
// restore the original file
defer func() {
copy("./testdata/agent-id-copy.yaml", "./testdata/agent-id.yaml")
os.Remove("./testdata/agent-id-copy.yaml")
}()
cfg, err := ParseAgentManagerConfig("./testdata/agent-id.yaml")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
assert.NotNil(t, cfg)
if cfg.ID == "" {
t.Errorf("expected agent ID to be set")
}
}