forked from replicatedhq/libyaml
/
component_test.go
119 lines (102 loc) · 2.63 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
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
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.MaxFiles\" == \"5\", got \"%s\"", c.LogOptions.MaxFiles)
}
if c.LogOptions.MaxSize != "100k" {
t.Errorf("expecting \"Component.MaxSize\" == \"100k\", got \"%s\"", c.LogOptions.MaxSize)
}
}
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
logs:
max_size: ""
max_files: ""
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"
containers: []
`
logReqs := libyaml.LogOptions{
MaxSize: "100k",
MaxFiles: "5",
}
c := libyaml.Component{
Name: "test",
Cluster: "true",
LogOptions: logReqs,
}
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))
}
}