-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add test for AddPVCToDeploymentConfig #551
Conversation
aad63fd
to
f49a33a
Compare
as of now, this is failing on panic error for
merge #554 which will add validation for pointers before dereferencing and validate by rerunning tests and then merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM after #554 is merged.
Needs re-basing, looks like a recent merge broke things. |
rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pkg/occlient/occlient_test.go
Outdated
t.Run(tt.name, func(t *testing.T) { | ||
fakeClient, fakeClientset := FakeNew() | ||
|
||
fakeClientset.AppClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pkg/occlient/occlient_test.go
Outdated
fakeClient, fakeClientset := FakeNew() | ||
|
||
fakeClientset.AppClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) { | ||
return true, nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should return the updated dc instead of nil and verify that the dc was updated with the proper values as done in
odo/pkg/occlient/occlient_test.go
Line 1337 in e8e223b
updatedDc := fkclientset.BuildClientset.Actions()[1].(ktesting.UpdateAction).GetObject().(*buildv1.BuildConfig) |
Also we should check that update was called on the correct dc by verifying against the name of the dc
odo/pkg/occlient/occlient_test.go
Lines 1323 to 1326 in e8e223b
buildConfig := action.(ktesting.UpdateAction).GetObject().(*buildv1.BuildConfig) | |
if buildConfig.Name != tt.buildConfigName { | |
return true, nil, fmt.Errorf("'update' was called with wrong buildConfig name") | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it is good to validate the values with which the function is being called but in this specific case there is a random string generation involved here https://github.com/redhat-developer/odo/blob/master/pkg/occlient/occlient.go#L1333
so it won't be feasible.
will add validation for the number of action performed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@syamgk The random string generation is only for the volumeName and we can leave that or check that if the volumeName is generated. In the returned DC, we should test the other parts, like if the pvcClaimName is the same as the one passed to the function and also the volumeMount Path is the same as the path passed to the function.
Also we should check if the update reactor was called with the correct dc name passed to the function because we might end up calling update on the wrong dc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added validation for the presence of mounts and with passing volume names & rebased
now ready for review
eb3ef1c
to
adf6998
Compare
9c54d63
to
4cd7e79
Compare
pkg/occlient/occlient_test.go
Outdated
fakeClient, fakeClientset := FakeNew() | ||
|
||
fakeClientset.AppsClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) { | ||
return true, nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we should check if the update reactor was called with the correct dc name passed to the function like
odo/pkg/occlient/occlient_test.go
Lines 1323 to 1326 in e8e223b
buildConfig := action.(ktesting.UpdateAction).GetObject().(*buildv1.BuildConfig) | |
if buildConfig.Name != tt.buildConfigName { | |
return true, nil, fmt.Errorf("'update' was called with wrong buildConfig name") | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
pkg/occlient/occlient_test.go
Outdated
} | ||
if found == false { | ||
t.Errorf("expected Volume mount path %v not found", tt.args.path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also have a test for this part of the code i.e the volumes, check the volume name as before and that the claimName is the same as desired
Lines 1339 to 1346 in 4cd7e79
dc.Spec.Template.Spec.Volumes = append(dc.Spec.Template.Spec.Volumes, corev1.Volume{ | |
Name: volumeName, | |
VolumeSource: corev1.VolumeSource{ | |
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ | |
ClaimName: pvc, | |
}, | |
}, | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added validation for this
6d7ebd0
to
3f0cb6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
pkg/occlient/occlient_test.go
Outdated
wantErr bool | ||
}{ | ||
{ | ||
name: "Test case : valid dc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add "Test case 1". Add numbers to each test case name
pkg/occlient/occlient_test.go
Outdated
}, | ||
}, | ||
}, | ||
pvc: "testglocks volume", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glocks? Not too sure what this name means.
pkg/occlient/occlient_test.go
Outdated
}, | ||
}, | ||
}, | ||
pvc: "my xx voulme", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better name maybe :). test-volume?
pkg/occlient/occlient_test.go
Outdated
}, | ||
}, | ||
}, | ||
pvc: "my xx voulme", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test-volume
pkg/occlient/occlient_test.go
Outdated
t.Errorf("expected 1 action in GetPVCFromName got: %v", fakeClientset.AppsClientset.Actions()) | ||
} | ||
updatedDc := fakeClientset.AppsClientset.Actions()[0].(ktesting.UpdateAction).GetObject().(*appsv1.DeploymentConfig) | ||
// creating a flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should try to add some spacing between separate sections of code. For example, add just one-line of space between the checks above and this section. Makes everything a bit less clustered.
pkg/occlient/occlient_test.go
Outdated
if tt.args.path == updatedDc.Spec.Template.Spec.Containers[0].VolumeMounts[bb].MountPath { | ||
found = true | ||
if !strings.Contains(updatedDc.Spec.Template.Spec.Containers[0].VolumeMounts[bb].Name, tt.args.pvc) { | ||
t.Errorf("pvc name not matching with the specived value got: %v, expected %v", updatedDc.Spec.Template.Spec.Containers[0].VolumeMounts[bb].Name, tt.args.pvc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@cdrage Pr is updated and ready for review now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
literally the smallest nitpick ever, once that's done, LGTM / merge away!
pkg/occlient/occlient_test.go
Outdated
}) | ||
err := fakeClient.AddPVCToDeploymentConfig(tt.args.dc, tt.args.pvc, tt.args.path) | ||
|
||
//Checks for error in positive cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space after //
add test for AddPVCToDeploymentConfig
add test for AddPVCToDeploymentConfig
+ fixing the format mismatch