-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Client tests #43
Client tests #43
Conversation
seans3
commented
Jun 15, 2018
- First pass at tests for client.go
- Currently 79.6% coverage
/assign droot |
@seans3 error should be legit now. Looks like a linting 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.
@seans3 changes are looking good, have some comments.
pkg/client/client_test.go
Outdated
dgvk := dgv.WithKind("Deployment") | ||
ngvk := ngv.WithKind("Node") | ||
scheme.AddKnownTypeWithName(dgvk, dep) | ||
scheme.AddKnownTypeWithName(ngvk, node) |
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.
client
users should not be required to register core types, by default, client
should use scheme from the core.
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.
Done.
@@ -134,16 +169,25 @@ var _ = Describe("Client", func() { | |||
close(done) | |||
}) | |||
|
|||
It("should create a new object from an unstructured object", func() { | |||
It("should create a new object from an unstructured object", func(done Done) { |
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.
Most of the time, our users are going to be using the core/custom types but unstructured. So not sure if unstructured test really helps ?
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.
Phil asked to do the unstructured, which gets slightly better code coverage. So let's go with it for now.
// TODO(seans3): implement these | ||
By("creating client with empty Scheme") | ||
emptyScheme := runtime.NewScheme() | ||
cl, err := client.New(cfg, client.Options{Scheme: emptyScheme}) |
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 can make it more closer to the actual user's usecase where: we create the cl
without specifying the scheme so that client is initialized with default scheme which understands the core-type resources and then use a custom struct (we can define one in this test file) for Create method and it should fail.
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.
Its good to check that the provided scheme is actually used though :)
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'll add a TODO for this. I don't want this PR to take much longer, so I'll address further checks in a future PR.
pkg/client/client_test.go
Outdated
dep.Annotations = map[string]string{"foo": "bar"} | ||
err = cl.Update(context.TODO(), dep) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("writing the result back to the go struct") | ||
By("validating updated Deployment exists") | ||
actual, err := clientset.AppsV1().Deployments(ns).Get(dep.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) |
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 aren't validating if the object got updated here.
actual, err := clientset.AppsV1().Deployments(ns).Get(dep.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(actual).NotTo(BeNil()) | ||
|
||
close(done) | ||
}) | ||
|
||
It("should update an existing new object from an unstructured object", func() { | ||
// TODO(seans3): implement these | ||
It("should update an existing new object from an unstructured object", func(done Done) { |
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.
As I said earlier, not sure if unstructured
tests help our usecase ?
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.
Phil asked to do the unstructured, which gets slightly better code coverage. So let's go with it for now.
|
||
By("fetching newly created unstructured Deployment") | ||
actual, err := clientset.AppsV1().Deployments(ns).Get(dep.Name, metav1.GetOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) |
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 aren't verifying the update actually happened.
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.
Doesn't this line do that:
Expect(actual.Annotations["foo"]).To(Equal("bar"))
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 just pushed this commit to address Sunil's concern.
It("should fail if the object cannot be mapped to a GVK", func(done Done) { | ||
By("creating client with empty Scheme") | ||
emptyScheme := runtime.NewScheme() | ||
cl, err := client.New(cfg, client.Options{Scheme: emptyScheme}) |
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.
same comment as earlier about not specifying the scheme.
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 think it makes it easier to check for things not in the Scheme if an empty one is passed in
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.
For this one, I'll keep the empty scheme.
|
||
By("creating the pod, since required field Containers is empty") | ||
err = cl.Create(context.TODO(), pod) | ||
Expect(err).To(HaveOccurred()) |
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.
Would you also check the error message to make sure it is actually the expected message and not something unrelated?
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.
Done
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.
Removing this test. The local versus travis tests vary.
Locally: Pod "pod-11" is invalid: spec.containers: Required value
Travis: pods "pod-11" is forbidden: error looking up service account default/default: serviceaccount "default" not found
For now I'm removing the substring test.
/lgtm |
/approve |
New changes are detected. LGTM label has been removed. |
/lgtm |
@seans3: you cannot LGTM your own PR. In response to this:
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. |
Change watching events to use interface instead of struct