@@ -11,6 +11,14 @@ import (
11
11
"testing"
12
12
)
13
13
14
+ func copyMap (originalMap map [string ]interface {}) map [string ]interface {} {
15
+ newMap := make (map [string ]interface {})
16
+ for k , v := range originalMap {
17
+ newMap [k ] = v
18
+ }
19
+ return newMap
20
+ }
21
+
14
22
var rdEdgeNodeEmptyOutput = map [string ]interface {}{
15
23
"adminstate" : "" ,
16
24
"adminstate_config" : "" ,
@@ -145,11 +153,49 @@ var efoEdgeNodeFullCfg = map[string]interface{}{
145
153
"utype" : "" ,
146
154
}
147
155
156
+ var rdEdgeNodeNilProjectId = map [string ]interface {}{
157
+ "name" : "sample-EdgeNode" ,
158
+ "id" : "SAMPLE-EdgeNode-ID" ,
159
+ "adminstate" : "" ,
160
+ "adminstate_config" : "ADMIN_STATE_ACTIVE" ,
161
+ "eve_image_version" : "6.8.2-kvm-amd64" ,
162
+ "interface" : []interface {}{},
163
+ "model_id" : "Test Model" ,
164
+ }
165
+
166
+ func rdEdgeNodeNilProjectIdOutput () map [string ]interface {} {
167
+ newMap := copyMap (rdEdgeNodeEmptyOutput )
168
+ newMap ["eve_image_version" ] = rdEdgeNodeNilProjectId ["eve_image_version" ]
169
+ newMap ["id" ] = rdEdgeNodeNilProjectId ["id" ]
170
+ newMap ["interface" ] = rdEdgeNodeNilProjectId ["interface" ]
171
+ newMap ["name" ] = rdEdgeNodeNilProjectId ["name" ]
172
+ return newMap
173
+ }
174
+
175
+ var rdEdgeNodeEmptyProjectId = map [string ]interface {}{
176
+ "name" : "sample-EdgeNode" ,
177
+ "id" : "SAMPLE-EdgeNode-ID" ,
178
+ "adminstate" : "" ,
179
+ "adminstate_config" : "ADMIN_STATE_ACTIVE" ,
180
+ "eve_image_version" : "6.8.2-kvm-amd64" ,
181
+ "interface" : []interface {}{},
182
+ "model_id" : "Test Model" ,
183
+ "project_id" : "" ,
184
+ }
185
+
186
+ func rdEdgeNodeUpdateProjectIdToNilOutput () map [string ]interface {} {
187
+ newMap := copyMap (rdEdgeNodeNilProjectIdOutput ())
188
+ newMap ["project_id" ] = "SampleProjectID"
189
+ return newMap
190
+ }
191
+
148
192
// In each test case, call rdXXX to get the appropriate config struct,
149
193
// feed it to flattenXXX, verify output of flattenXXX is same as input
150
194
func TestRDEdgeNodeConfig (t * testing.T ) {
151
195
cases := []struct {
152
196
input map [string ]interface {}
197
+ update bool
198
+ update_project_id bool
153
199
description string
154
200
expectError bool
155
201
expectedFlattenedOutput map [string ]interface {}
@@ -167,6 +213,27 @@ func TestRDEdgeNodeConfig(t *testing.T) {
167
213
expectError : false ,
168
214
expectedFlattenedOutput : efoEdgeNodeFullCfg ,
169
215
},
216
+ {
217
+ input : rdEdgeNodeNilProjectId ,
218
+ description : "Nil Project Create" ,
219
+ expectError : true ,
220
+ expectedFlattenedOutput : rdEdgeNodeNilProjectIdOutput (),
221
+ },
222
+ {
223
+ input : rdEdgeNodeNilProjectId ,
224
+ description : "Update non-nil project id to Nil" ,
225
+ expectError : false ,
226
+ update : true ,
227
+ update_project_id : true ,
228
+ expectedFlattenedOutput : rdEdgeNodeUpdateProjectIdToNilOutput (),
229
+ },
230
+ {
231
+ input : rdEdgeNodeEmptyProjectId ,
232
+ description : "Empty Project Update" ,
233
+ expectError : false ,
234
+ update : true ,
235
+ expectedFlattenedOutput : rdEdgeNodeNilProjectIdOutput (),
236
+ },
170
237
}
171
238
172
239
for _ , c := range cases {
@@ -179,18 +246,23 @@ func TestRDEdgeNodeConfig(t *testing.T) {
179
246
cfg .Name = & name
180
247
cfg .ID , ok = c .input ["id" ].(string )
181
248
cfg .BaseImage = cfgBaseosForEveVersionStr (rdEntryStr (rd , "eve_image_version" ))
182
- err := rdDeviceConfig (cfg , rd , true )
249
+ if c .update_project_id {
250
+ project_id := "SampleProjectID"
251
+ cfg .ProjectID = & project_id
252
+ }
253
+ err := rdDeviceConfig (cfg , rd , ! c .update )
183
254
if err != nil {
184
255
if ! c .expectError {
185
256
t .Fatalf ("Test Failed: %s\n " +
186
257
"Unexpected error from updateEdgeNodeCfgFromResourceData.\n " +
187
258
"Error: %+v\n " , c .description , err .Error ())
188
259
}
189
- } else {
190
- if c .expectError {
191
- t .Fatalf ("Test Failed: %s. Expecting Error, but did not get one" ,
192
- c .description )
193
- }
260
+ // No point in continuing cfg is invalid
261
+ continue
262
+ }
263
+ if c .expectError {
264
+ t .Fatalf ("Test Failed: %s. Expecting Error, but did not get one" ,
265
+ c .description )
194
266
}
195
267
out := flattenDeviceConfig (cfg , false )
196
268
err = verifyFlattenOutput (zschemas .EdgeNodeSchema , out , c .expectAllSchemaKeys )
@@ -202,7 +274,7 @@ func TestRDEdgeNodeConfig(t *testing.T) {
202
274
t .Fatalf ("Test Failed: %s\n " +
203
275
"Error matching Flattened output and input.\n " +
204
276
"Output: %#v\n " +
205
- "Input : %#v\n " +
277
+ "expectedFlattenedOutput : %#v\n " +
206
278
"Diff: %#v" , c .description , out , c .expectedFlattenedOutput , diff )
207
279
}
208
280
}
0 commit comments