forked from replicatedhq/libyaml
/
container_test.go
172 lines (156 loc) · 3.64 KB
/
container_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package libyaml
import (
"testing"
"github.com/andreychernih/yaml"
)
func TestContainerUnmarshalYAML(t *testing.T) {
s := `source: public
image_name: test
display_name: Test Container
version: ""
privileged: false
hostname: ""
cmd: ""
cluster: false
publish_events: []
config_files: []
customer_files: []
env_vars: []
ports: []
volumes: []
support_files: []
support_commands: []`
var c Container
if err := yaml.Unmarshal([]byte(s), &c); err != nil {
t.Fatal(err)
}
if c.Source != "public" {
t.Errorf("expecting \"Container.Source\" == \"public\", got \"%s\"", c.Source)
}
if c.ImageName != "test" {
t.Errorf("expecting \"Container.ImageName\" == \"test\", got \"%s\"", c.ImageName)
}
if c.DisplayName != "Test Container" {
t.Errorf("expecting \"Container.DisplayName\" == \"Test Container\", got \"%s\"", c.ImageName)
}
if c.Cluster {
t.Error("expecting \"Container.Cluster\" to be false")
}
if c.ClusterInstanceCount.Initial != 0 {
t.Errorf("expecting \"Container.ClusterInstanceCount.Initial\" == 0, got \"%d\"", c.ClusterInstanceCount.Initial)
}
if c.ClusterInstanceCount.ThresholdHealthy != 0 {
t.Errorf("expecting \"Container.ClusterInstanceCount.ThresholdHealthy\" == 0, got \"%d\"", c.ClusterInstanceCount.ThresholdHealthy)
}
}
func TestContainerUnmarshalYAMLCluster(t *testing.T) {
s := `source: public
image_name: test
display_name: Test Container
version: ""
privileged: false
hostname: ""
cmd: ""
cluster: true
publish_events: []
config_files: []
customer_files: []
env_vars: []
ports: []
volumes: []
support_files: []
support_commands: []`
var c Container
if err := yaml.Unmarshal([]byte(s), &c); err != nil {
t.Fatal(err)
}
if c.Source != "public" {
t.Errorf("expecting \"Container.Source\" == \"public\", got \"%s\"", c.Source)
}
if c.ImageName != "test" {
t.Errorf("expecting \"Container.ImageName\" == \"test\", got \"%s\"", c.ImageName)
}
if c.DisplayName != "Test Container" {
t.Errorf("expecting \"Container.DisplayName\" == \"Test Container\", got \"%s\"", c.ImageName)
}
if !c.Cluster {
t.Error("expecting \"Container.Cluster\" to be true")
}
if c.ClusterInstanceCount.Initial != 1 {
t.Errorf("expecting \"Container.ClusterInstanceCount.Initial\" == 1, got \"%d\"", c.ClusterInstanceCount.Initial)
}
if c.ClusterInstanceCount.ThresholdHealthy != 0 {
t.Errorf("expecting \"Container.ClusterInstanceCount.ThresholdHealthy\" == 0, got \"%d\"", c.ClusterInstanceCount.ThresholdHealthy)
}
}
func TestContainerMarshalYAML(t *testing.T) {
s := `source: public
image_name: test
display_name: ""
version: ""
privileged: false
hostname: ""
cmd: ""
ephemeral: ""
cluster: false
restart: null
publish_events: []
config_files: []
customer_files: []
env_vars: []
ports: []
volumes: []
support_files: []
support_commands: []
when: ""
`
c := Container{
Source: "public",
ImageName: "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 TestContainerMarshalYAMLCluster(t *testing.T) {
s := `source: public
image_name: test
display_name: ""
version: ""
privileged: false
hostname: ""
cmd: ""
ephemeral: ""
cluster: true
restart: null
cluster_instance_count:
initial: 1
threshold_healthy: 0
publish_events: []
config_files: []
customer_files: []
env_vars: []
ports: []
volumes: []
support_files: []
support_commands: []
when: ""
`
c := Container{
Source: "public",
ImageName: "test",
Cluster: true,
}
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))
}
}