@@ -196,25 +196,6 @@ spec:
196
196
- --momentum=${trialParameters.momentum}
197
197
- --invalidParameter={'num_layers': 2, 'input_sizes': [32, 32, 3]}`
198
198
199
- validGetConfigMap1 := c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
200
- map [string ]string {templatePath : trialSpec }, nil )
201
-
202
- invalidConfigMapName := c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
203
- nil , errConfigMapNotFound )
204
-
205
- validGetConfigMap3 := c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
206
- map [string ]string {templatePath : trialSpec }, nil )
207
-
208
- invalidTemplate := c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
209
- map [string ]string {templatePath : invalidTrialSpec }, nil )
210
-
211
- gomock .InOrder (
212
- validGetConfigMap1 ,
213
- invalidConfigMapName ,
214
- validGetConfigMap3 ,
215
- invalidTemplate ,
216
- )
217
-
218
199
// We can't compare structures, because in ConfigMap trialSpec is a string and creationTimestamp was not added
219
200
expectedStr := `apiVersion: batch/v1
220
201
kind: Job
@@ -241,13 +222,17 @@ spec:
241
222
}
242
223
243
224
cases := map [string ]struct {
225
+ prepareConfigMap func ()
244
226
instance * experimentsv1beta1.Experiment
245
227
parameterAssignments []commonapiv1beta1.ParameterAssignment
246
228
wantRunSpecWithHyperParameters * unstructured.Unstructured
247
229
wantError error
248
230
}{
249
- // validGetConfigMap1 case
250
231
"Run with valid parameters" : {
232
+ prepareConfigMap : func () {
233
+ c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
234
+ map [string ]string {templatePath : trialSpec }, nil )
235
+ },
251
236
instance : func () * experimentsv1beta1.Experiment {
252
237
i := newFakeInstance ()
253
238
i .Spec .TrialTemplate .TrialSource = experimentsv1beta1.TrialSource {
@@ -262,8 +247,11 @@ spec:
262
247
parameterAssignments : newFakeParameterAssignment (),
263
248
wantRunSpecWithHyperParameters : expectedRunSpec ,
264
249
},
265
- // invalidConfigMapName case
266
250
"Invalid ConfigMap name" : {
251
+ prepareConfigMap : func () {
252
+ c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
253
+ nil , errConfigMapNotFound )
254
+ },
267
255
instance : func () * experimentsv1beta1.Experiment {
268
256
i := newFakeInstance ()
269
257
i .Spec .TrialTemplate .TrialSource = experimentsv1beta1.TrialSource {
@@ -276,8 +264,11 @@ spec:
276
264
parameterAssignments : newFakeParameterAssignment (),
277
265
wantError : errConfigMapNotFound ,
278
266
},
279
- // validGetConfigMap3 case
280
267
"Invalid template path in ConfigMap name" : {
268
+ prepareConfigMap : func () {
269
+ c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
270
+ map [string ]string {templatePath : trialSpec }, nil )
271
+ },
281
272
instance : func () * experimentsv1beta1.Experiment {
282
273
i := newFakeInstance ()
283
274
i .Spec .TrialTemplate .TrialSource = experimentsv1beta1.TrialSource {
@@ -292,10 +283,13 @@ spec:
292
283
parameterAssignments : newFakeParameterAssignment (),
293
284
wantError : errTrialTemplateNotFound ,
294
285
},
295
- // invalidTemplate case
296
286
// Trial template is a string in ConfigMap
297
287
// Because of that, user can specify not valid unstructured template
298
288
"Invalid trial spec in ConfigMap" : {
289
+ prepareConfigMap : func () {
290
+ c .EXPECT ().GetConfigMap (gomock .Any (), gomock .Any ()).Return (
291
+ map [string ]string {templatePath : invalidTrialSpec }, nil )
292
+ },
299
293
instance : func () * experimentsv1beta1.Experiment {
300
294
i := newFakeInstance ()
301
295
i .Spec .TrialTemplate .TrialSource = experimentsv1beta1.TrialSource {
@@ -314,6 +308,7 @@ spec:
314
308
315
309
for name , tc := range cases {
316
310
t .Run (name , func (t * testing.T ) {
311
+ tc .prepareConfigMap ()
317
312
got , err := p .GetRunSpecWithHyperParameters (tc .instance , "trial-name" , "trial-namespace" , tc .parameterAssignments )
318
313
if diff := cmp .Diff (tc .wantError , err , cmpopts .EquateErrors ()); len (diff ) != 0 {
319
314
t .Errorf ("Unexpected error from GetRunSpecWithHyperParameters (-want,+got):\n %s" , diff )
0 commit comments