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

Client tests #43

Merged
merged 1 commit into from
Jun 19, 2018
Merged

Client tests #43

merged 1 commit into from
Jun 19, 2018

Conversation

seans3
Copy link
Contributor

@seans3 seans3 commented Jun 15, 2018

  • First pass at tests for client.go
  • Currently 79.6% coverage

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 15, 2018
@seans3
Copy link
Contributor Author

seans3 commented Jun 15, 2018

/assign droot
/assign pwittrock

@pwittrock
Copy link
Contributor

@seans3 error should be legit now. Looks like a linting error.

Copy link
Contributor

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

dgvk := dgv.WithKind("Deployment")
ngvk := ngv.WithKind("Node")
scheme.AddKnownTypeWithName(dgvk, dep)
scheme.AddKnownTypeWithName(ngvk, node)
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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})
Copy link
Contributor

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

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())
Copy link
Contributor

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) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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())
Copy link
Contributor

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.

Copy link
Contributor

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"))

Copy link
Contributor Author

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})
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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())
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

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.

@pwittrock
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
@pwittrock
Copy link
Contributor

/approve

@pwittrock pwittrock added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 19, 2018
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
@seans3
Copy link
Contributor Author

seans3 commented Jun 19, 2018

/lgtm

@k8s-ci-robot
Copy link
Contributor

@seans3: you cannot LGTM your own PR.

In response to this:

/lgtm

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.

@pwittrock pwittrock added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2018
@k8s-ci-robot k8s-ci-robot merged commit 89a112f into kubernetes-sigs:master Jun 19, 2018
justinsb pushed a commit to justinsb/controller-runtime that referenced this pull request Dec 7, 2018
DirectXMan12 pushed a commit that referenced this pull request Jan 31, 2020
Change watching events to use interface instead of struct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants