Skip to content

Commit

Permalink
fix order of mock method calls
Browse files Browse the repository at this point in the history
Signed-off-by: tariq-hasan <[email protected]>
  • Loading branch information
tariq-hasan committed Aug 18, 2024
1 parent 52c55c6 commit c8b7f49
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions pkg/controller.v1beta1/experiment/manifest/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,6 @@ spec:
- --momentum=${trialParameters.momentum}
- --invalidParameter={'num_layers': 2, 'input_sizes': [32, 32, 3]}`

validGetConfigMap1 := c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: trialSpec}, nil)

invalidConfigMapName := c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
nil, errConfigMapNotFound)

validGetConfigMap3 := c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: trialSpec}, nil)

invalidTemplate := c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: invalidTrialSpec}, nil)

gomock.InOrder(
validGetConfigMap1,
invalidConfigMapName,
validGetConfigMap3,
invalidTemplate,
)

// We can't compare structures, because in ConfigMap trialSpec is a string and creationTimestamp was not added
expectedStr := `apiVersion: batch/v1
kind: Job
Expand All @@ -241,13 +222,15 @@ spec:
}

cases := map[string]struct {
mockConfigMapGetter *gomock.Call
instance *experimentsv1beta1.Experiment
parameterAssignments []commonapiv1beta1.ParameterAssignment
wantRunSpecWithHyperParameters *unstructured.Unstructured
wantError error
}{
// validGetConfigMap1 case
"Run with valid parameters": {
mockConfigMapGetter: c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: trialSpec}, nil),
instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Spec.TrialTemplate.TrialSource = experimentsv1beta1.TrialSource{
Expand All @@ -262,8 +245,9 @@ spec:
parameterAssignments: newFakeParameterAssignment(),
wantRunSpecWithHyperParameters: expectedRunSpec,
},
// invalidConfigMapName case
"Invalid ConfigMap name": {
mockConfigMapGetter: c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
nil, errConfigMapNotFound),
instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Spec.TrialTemplate.TrialSource = experimentsv1beta1.TrialSource{
Expand All @@ -276,8 +260,9 @@ spec:
parameterAssignments: newFakeParameterAssignment(),
wantError: errConfigMapNotFound,
},
// validGetConfigMap3 case
"Invalid template path in ConfigMap name": {
mockConfigMapGetter: c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: trialSpec}, nil),
instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Spec.TrialTemplate.TrialSource = experimentsv1beta1.TrialSource{
Expand All @@ -292,10 +277,11 @@ spec:
parameterAssignments: newFakeParameterAssignment(),
wantError: errTrialTemplateNotFound,
},
// invalidTemplate case
// Trial template is a string in ConfigMap
// Because of that, user can specify not valid unstructured template
"Invalid trial spec in ConfigMap": {
mockConfigMapGetter: c.EXPECT().GetConfigMap(gomock.Any(), gomock.Any()).Return(
map[string]string{templatePath: invalidTrialSpec}, nil),
instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Spec.TrialTemplate.TrialSource = experimentsv1beta1.TrialSource{
Expand Down

0 comments on commit c8b7f49

Please sign in to comment.