1
1
package commands
2
2
3
3
import (
4
+ "bytes"
5
+ "strings"
4
6
"testing"
5
7
6
8
"github.com/deislabs/cnab-go/bundle"
@@ -26,7 +28,11 @@ overridden: bar`))
26
28
actual := map [string ]string {
27
29
"overridden" : "foo" ,
28
30
}
29
- err := withFileParameters ([]string {tmpDir .Join ("params.yaml" )})(bundle , actual )
31
+ err := withFileParameters ([]string {tmpDir .Join ("params.yaml" )})(
32
+ & mergeBundleConfig {
33
+ bundle : bundle ,
34
+ params : actual ,
35
+ })
30
36
assert .NilError (t , err )
31
37
expected := map [string ]string {
32
38
"param1.param2" : "value1" ,
@@ -42,7 +48,11 @@ func TestWithCommandLineParameters(t *testing.T) {
42
48
"overridden" : "foo" ,
43
49
}
44
50
45
- err := withCommandLineParameters ([]string {"param1.param2=value1" , "param3=3" , "overridden=bar" })(bundle , actual )
51
+ err := withCommandLineParameters ([]string {"param1.param2=value1" , "param3=3" , "overridden=bar" })(
52
+ & mergeBundleConfig {
53
+ bundle : bundle ,
54
+ params : actual ,
55
+ })
46
56
assert .NilError (t , err )
47
57
expected := map [string ]string {
48
58
"param1.param2" : "value1" ,
@@ -135,7 +145,10 @@ func TestWithOrchestratorParameters(t *testing.T) {
135
145
for _ , testCase := range testCases {
136
146
t .Run (testCase .name , func (t * testing.T ) {
137
147
actual := map [string ]string {}
138
- err := withOrchestratorParameters ("kubernetes" , "my-namespace" )(testCase .bundle , actual )
148
+ err := withOrchestratorParameters ("kubernetes" , "my-namespace" )(& mergeBundleConfig {
149
+ bundle : testCase .bundle ,
150
+ params : actual ,
151
+ })
139
152
assert .NilError (t , err )
140
153
assert .Assert (t , cmp .DeepEqual (actual , testCase .expected ))
141
154
})
@@ -144,12 +157,12 @@ func TestWithOrchestratorParameters(t *testing.T) {
144
157
145
158
func TestMergeBundleParameters (t * testing.T ) {
146
159
t .Run ("Override Order" , func (t * testing.T ) {
147
- first := func (b * bundle. Bundle , params map [ string ] string ) error {
148
- params ["param" ] = "first"
160
+ first := func (c * mergeBundleConfig ) error {
161
+ c . params ["param" ] = "first"
149
162
return nil
150
163
}
151
- second := func (b * bundle. Bundle , params map [ string ] string ) error {
152
- params ["param" ] = "second"
164
+ second := func (c * mergeBundleConfig ) error {
165
+ c . params ["param" ] = "second"
153
166
return nil
154
167
}
155
168
bundle := prepareBundle (withParameterAndDefault ("param" , "string" , "default" ))
@@ -177,8 +190,8 @@ func TestMergeBundleParameters(t *testing.T) {
177
190
})
178
191
179
192
t .Run ("Converting values" , func (t * testing.T ) {
180
- withIntValue := func (b * bundle. Bundle , params map [ string ] string ) error {
181
- params ["param" ] = "1"
193
+ withIntValue := func (c * mergeBundleConfig ) error {
194
+ c . params ["param" ] = "1"
182
195
return nil
183
196
}
184
197
bundle := prepareBundle (withParameter ("param" , "integer" ))
@@ -202,20 +215,33 @@ func TestMergeBundleParameters(t *testing.T) {
202
215
assert .Assert (t , cmp .DeepEqual (i .Parameters , expected ))
203
216
})
204
217
205
- t .Run ("Undefined parameter is rejected" , func (t * testing.T ) {
206
- withUndefined := func (b * bundle.Bundle , params map [string ]string ) error {
207
- params ["param" ] = "1"
218
+ t .Run ("Undefined parameter throws warning" , func (t * testing.T ) {
219
+ withUndefined := func (c * mergeBundleConfig ) error {
220
+ c .params ["param" ] = "1"
221
+ return nil
222
+ }
223
+ bundle := prepareBundle ()
224
+ i := & store.Installation {Claim : claim.Claim {Bundle : bundle }}
225
+ buf := new (bytes.Buffer )
226
+ err := mergeBundleParameters (i , withUndefined , withErrorWriter (buf ))
227
+ assert .NilError (t , err )
228
+ assert .Assert (t , strings .Contains (buf .String (), "is not defined in the bundle" ))
229
+ })
230
+
231
+ t .Run ("Undefined parameter with strict mode is rejected" , func (t * testing.T ) {
232
+ withUndefined := func (c * mergeBundleConfig ) error {
233
+ c .params ["param" ] = "1"
208
234
return nil
209
235
}
210
236
bundle := prepareBundle ()
211
237
i := & store.Installation {Claim : claim.Claim {Bundle : bundle }}
212
- err := mergeBundleParameters (i , withUndefined )
238
+ err := mergeBundleParameters (i , withUndefined , withStrictMode ( true ) )
213
239
assert .ErrorContains (t , err , "is not defined in the bundle" )
214
240
})
215
241
216
242
t .Run ("Invalid type is rejected" , func (t * testing.T ) {
217
- withIntValue := func (b * bundle. Bundle , params map [ string ] string ) error {
218
- params ["param" ] = "foo"
243
+ withIntValue := func (c * mergeBundleConfig ) error {
244
+ c . params ["param" ] = "foo"
219
245
return nil
220
246
}
221
247
bundle := prepareBundle (withParameter ("param" , "integer" ))
@@ -225,8 +251,8 @@ func TestMergeBundleParameters(t *testing.T) {
225
251
})
226
252
227
253
t .Run ("Invalid value is rejected" , func (t * testing.T ) {
228
- withInvalidValue := func (b * bundle. Bundle , params map [ string ] string ) error {
229
- params ["param" ] = "invalid"
254
+ withInvalidValue := func (c * mergeBundleConfig ) error {
255
+ c . params ["param" ] = "invalid"
230
256
return nil
231
257
}
232
258
bundle := prepareBundle (withParameterAndValues ("param" , "string" , []interface {}{"valid" }))
0 commit comments