-
Notifications
You must be signed in to change notification settings - Fork 14
/
component_test.go
139 lines (122 loc) · 3.25 KB
/
component_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package libyaml_test
import (
"testing"
"github.com/replicatedhq/libyaml"
yaml "gopkg.in/yaml.v2"
)
func TestComponentUnmarshalYAML(t *testing.T) {
s := `name: test
cluster: false
logs:
max_size: 100k
max_files: 5
log_config:
type: journald
config:
tag: my-service
containers: []`
var c libyaml.Component
if err := yaml.Unmarshal([]byte(s), &c); err != nil {
t.Fatal(err)
}
if c.Name != "test" {
t.Errorf("expecting \"Component.Name\" == \"test\", got \"%s\"", c.Name)
}
if c.Cluster != "false" {
t.Error("expecting \"Component.Cluster\" to be \"false\"")
}
if c.ClusterHostCount.Min != "" {
t.Errorf("expecting \"Component.ClusterHostCount.Min\" == \"\", got \"%s\"", c.ClusterHostCount.Min)
}
if c.ClusterHostCount.ThresholdHealthy != "" {
t.Errorf("expecting \"Component.ClusterHostCount.ThresholdHealthy\" == \"\", got \"%s\"", c.ClusterHostCount.ThresholdHealthy)
}
if c.LogOptions.MaxFiles != "5" {
t.Errorf("expecting \"Component.LogOptions.MaxFiles\" == \"5\", got \"%s\"", c.LogOptions.MaxFiles)
}
if c.LogOptions.MaxSize != "100k" {
t.Errorf("expecting \"Component.LogOptions.MaxSize\" == \"100k\", got \"%s\"", c.LogOptions.MaxSize)
}
if c.LogConfig.Type != "journald" {
t.Errorf("expecting \"Component.LogConfig.Type\" == \"journald\", got \"%s\"", c.LogConfig.Type)
}
if c.LogConfig.Config == nil {
t.Errorf("\"Component.LogConfig.Config\" is nil")
} else if val, _ := c.LogConfig.Config["tag"]; val != "my-service" {
t.Errorf("expecting \"Component.LogConfig.Config[\"tag\"]\" == \"my-service\", got \"%s\"", val)
}
}
func TestComponentUnmarshalYAMLCluster(t *testing.T) {
s := `name: test
cluster: true
containers: []`
var c libyaml.Component
if err := yaml.Unmarshal([]byte(s), &c); err != nil {
t.Fatal(err)
}
if c.Name != "test" {
t.Errorf("expecting \"Component.Name\" == \"test\", got \"%s\"", c.Name)
}
if c.Cluster != "true" {
t.Error("expecting \"Component.Cluster\" to be \"true\"")
}
if c.ClusterHostCount.Min != "" {
t.Errorf("expecting \"Component.ClusterHostCount.Min\" == \"\", got \"%s\"", c.ClusterHostCount.Min)
}
if c.ClusterHostCount.ThresholdHealthy != "" {
t.Errorf("expecting \"Component.ClusterHostCount.ThresholdHealthy\" == \"\", got \"%s\"", c.ClusterHostCount.ThresholdHealthy)
}
}
func TestComponentMarshalYAML(t *testing.T) {
s := `name: test
cluster: false
containers: []
`
c := libyaml.Component{
Name: "test",
Cluster: "false",
}
b, err := yaml.Marshal(c)
if err != nil {
t.Fatal(err)
}
if string(b) != s {
t.Errorf("unexpected marshalled YAML,\nexpecting\n%s\ngot\n%s", s, string(b))
}
}
func TestComponentMarshalYAMLCluster(t *testing.T) {
s := `name: test
cluster: true
logs:
max_size: 100k
max_files: "5"
log_config:
type: journald
config:
tag: my-service
containers: []
`
logOptions := libyaml.LogOptions{
MaxSize: "100k",
MaxFiles: "5",
}
logConfig := libyaml.LogConfig{
Type: "journald",
Config: map[string]string{
"tag": "my-service",
},
}
c := libyaml.Component{
Name: "test",
Cluster: "true",
LogOptions: logOptions,
LogConfig: logConfig,
}
b, err := yaml.Marshal(c)
if err != nil {
t.Fatal(err)
}
if string(b) != s {
t.Errorf("unexpected marshalled YAML,\nexpecting\n%s\ngot\n%s", s, string(b))
}
}