Skip to content
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

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

syamgk
Copy link
Member

@syamgk syamgk commented Jun 28, 2018

add test for AddPVCToDeploymentConfig

+ fixing the format mismatch

@syamgk syamgk added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. do not review labels Jun 28, 2018
@syamgk syamgk removed do not review do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. labels Jun 29, 2018
@syamgk syamgk force-pushed the tstAddpvctoDc branch 4 times, most recently from aad63fd to f49a33a Compare June 29, 2018 09:41
@syamgk
Copy link
Member Author

syamgk commented Jun 29, 2018

as of now, this is failing on panic error for

- Test case : dc without container
 -Test case : dc without Template

merge #554 which will add validation for pointers before dereferencing and validate by rerunning tests and then merge

Copy link
Member

@cdrage cdrage left a 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.

@cdrage
Copy link
Member

cdrage commented Jul 10, 2018

Needs re-basing, looks like a recent merge broke things.

@cdrage cdrage added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Jul 10, 2018
@syamgk
Copy link
Member Author

syamgk commented Jul 19, 2018

rebased

@syamgk syamgk removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. labels Jul 19, 2018
Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

t.Run(tt.name, func(t *testing.T) {
fakeClient, fakeClientset := FakeNew()

fakeClientset.AppClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fakeClient, fakeClientset := FakeNew()

fakeClientset.AppClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, nil, nil
Copy link
Contributor

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

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

buildConfig := action.(ktesting.UpdateAction).GetObject().(*buildv1.BuildConfig)
if buildConfig.Name != tt.buildConfigName {
return true, nil, fmt.Errorf("'update' was called with wrong buildConfig name")
}

Copy link
Member Author

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

Copy link
Contributor

@mik-dass mik-dass Jul 26, 2018

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.

Copy link
Member Author

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

@mik-dass mik-dass added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Jul 26, 2018
@syamgk syamgk force-pushed the tstAddpvctoDc branch 2 times, most recently from eb3ef1c to adf6998 Compare July 26, 2018 16:40
@syamgk syamgk removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Jul 26, 2018
@syamgk syamgk force-pushed the tstAddpvctoDc branch 2 times, most recently from 9c54d63 to 4cd7e79 Compare July 27, 2018 05:16
fakeClient, fakeClientset := FakeNew()

fakeClientset.AppsClientset.PrependReactor("update", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, nil, nil
Copy link
Contributor

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

buildConfig := action.(ktesting.UpdateAction).GetObject().(*buildv1.BuildConfig)
if buildConfig.Name != tt.buildConfigName {
return true, nil, fmt.Errorf("'update' was called with wrong buildConfig name")
}
because we might end up calling update on the wrong dc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

}
if found == false {
t.Errorf("expected Volume mount path %v not found", tt.args.path)
}
Copy link
Contributor

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

odo/pkg/occlient/occlient.go

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,
},
},
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added validation for this

@redhat-developer redhat-developer deleted a comment from syamgk Jul 27, 2018
@syamgk syamgk force-pushed the tstAddpvctoDc branch 3 times, most recently from 6d7ebd0 to 3f0cb6f Compare July 27, 2018 09:49
Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

wantErr bool
}{
{
name: "Test case : valid dc",
Copy link
Member

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

},
},
},
pvc: "testglocks volume",
Copy link
Member

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.

},
},
},
pvc: "my xx voulme",
Copy link
Member

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?

},
},
},
pvc: "my xx voulme",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-volume

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
Copy link
Member

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.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specified

Copy link
Contributor

@ashetty1 ashetty1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mik-dass mik-dass added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 1, 2018
@syamgk syamgk removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 1, 2018
@syamgk
Copy link
Member Author

syamgk commented Aug 1, 2018

@cdrage Pr is updated and ready for review now

Copy link
Member

@cdrage cdrage left a 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!

})
err := fakeClient.AddPVCToDeploymentConfig(tt.args.dc, tt.args.pvc, tt.args.path)

//Checks for error in positive cases
Copy link
Member

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
@mik-dass mik-dass merged commit 4fa6a37 into redhat-developer:master Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants