Initial work on unit test for ./pkg/rest/core/fake rest client, addresses #860 #1009
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@crmejia great start. Do you have plans to write more tests in here? |
Yes, I plan to test the other functions and methods. Just not sure how to test |
@crmejia ok, sounds good. please ping me when you are ready for another review |
f(rw, request) | ||
|
||
if rw.getResponse().StatusCode != http.StatusOK && rw.headerSet { | ||
t.Fatal("Expected Status OK", http.StatusOK, "got", rw.getResponse().StatusCode) |
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 test is failing rest_client_test.go:162: Expected Status OK 200 got 404
Not sure why. My current URL is /apis/servicecatalog.k8s.io/v1alpha1/namespaces/ns1/tipe1/name1
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.
@crmejia this is failing because of the following code in the anonymous function that getItem
returns:
ns := mux.Vars(r)["namespace"]
tipe := mux.Vars(r)["type"]
name := mux.Vars(r)["name"]
The return values of those Vars
calls are empty because the keys ("namespace", "type", "name") are not registered with gorilla mux. The way to fix this is to register the route /apis/servicecatalog.k8s.io/v1alpha1/namespaces/{namespace}/{type}/{name}
with a new mux router, and then do a request to the gorilla mux router instead of directly to the handler.
Please let me know if that doesn't make sense, and I'm happy to go into more detail.
@crmejia do you plan to try to get this in? |
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
request, err := http.NewRequest("POST", tc.url, 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.
I still need to put the object in the body. Not sure how yet. Would something like this work?
/Users/crismarmejia/go/src/github.com/kubernetes-incubator/service-catalog/pkg/rest/core/fake/rest_client.go:321 +0x2b8
ps. I've noticed that users of the rest_client.go are not using the router but the methods on storage directly. Should I stop testing these functions and mark as the issue as completed(and move to other things)?
I'm closing this PR to see If it fixes the issue with the cla. I signed the cla with a different address than the one I use for GitHub. I updated my GH account but the issue persists. |
Not finished yet. Looking for some early feedback and direction.