Skip to content

Commit 517fee8

Browse files
committed
fix nil map bug
1 parent 680e4f2 commit 517fee8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,27 @@ func ParseConfig(b io.Reader) (*Config, error) {
147147
deploy.CloudInitPath = c.Common.CloudInitPath
148148
}
149149

150+
if deploy.Vars == nil {
151+
deploy.Vars = make(map[string]string)
152+
}
150153
for k, v := range c.Common.Vars {
151154
if _, ok := deploy.Vars[k]; !ok {
152155
deploy.Vars[k] = v
153156
}
154157
}
155158

159+
if deploy.Labels == nil {
160+
deploy.Labels = make(map[string]string)
161+
}
156162
for k, v := range c.Common.Labels {
157163
if _, ok := deploy.Labels[k]; !ok {
158164
deploy.Labels[k] = v
159165
}
160166
}
161167

168+
if deploy.Metadata == nil {
169+
deploy.Metadata = make(map[string]string)
170+
}
162171
for k, v := range c.Common.Metadata {
163172
if _, ok := deploy.Metadata[k]; !ok {
164173
deploy.Metadata[k] = v

config_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ deploys:
181181
assert.Equal(t, "12", c.Deploys[0].UpdatePolicy.MaxUnavailable)
182182
}
183183

184+
func TestNilMaps(t *testing.T) {
185+
config := `
186+
common:
187+
vars:
188+
var1: x
189+
labels:
190+
label1: x
191+
metadata:
192+
metadata1: x
193+
tags:
194+
- tag1
195+
196+
deploys:
197+
- name: test
198+
region: w
199+
instance_group: x
200+
instance_template_base: y
201+
instance_template: z
202+
`
203+
204+
_, err := ParseConfig(strings.NewReader(config))
205+
require.NoError(t, err)
206+
}
207+
184208
func TestExpandShellRe(t *testing.T) {
185209
in := `$foo $FOO ${foo} a${foo}b \$foo \${foo} a\${foo}b $foo-$foo $foo-${foo} $fo $f`
186210

0 commit comments

Comments
 (0)