Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Improve test coverage of Kubernetes package #1894

Merged
merged 3 commits into from
Mar 1, 2018

Conversation

ebaron
Copy link
Contributor

@ebaron ebaron commented Feb 9, 2018

This PR adds several tests for deployments_kubeclient.go, focusing on the API methods used by "deployments" controller. The new tests use JSON files as input containing mock Kubernetes/OpenShift resources. Likewise, existing communication with the OpenShift API server in deployments_kubeclient.go using YAML has been changed to JSON.

This PR also fixes a bug discovered during testing, where the pod list is incorrect due to using a pointer to a loop iteration variable. This has been changed to point to elements from the slice returned by Kubernetes. This bug was introduced recently when switching from the "apps" to "deployments" API.

One other thing changed by this PR is to return an empty array for pod statuses, when there are no pods in a deployment. In order to return an empty array in the JSON response, I had to specify the "pods" attribute as "Required" in the goa design. Previously, we would return a dummy entry of "0 Running".

@ebaron ebaron requested review from xcoulon and stooke February 9, 2018 23:36
@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-1

@codecov-io
Copy link

codecov-io commented Feb 10, 2018

Codecov Report

Merging #1894 into master will increase coverage by 2.39%.
The diff coverage is 31.38%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1894      +/-   ##
==========================================
+ Coverage   61.05%   63.44%   +2.39%     
==========================================
  Files         144      144              
  Lines       13366    13392      +26     
==========================================
+ Hits         8161     8497     +336     
+ Misses       4482     4084     -398     
- Partials      723      811      +88
Impacted Files Coverage Δ
kubernetes/deployments_kubeclient.go 52.07% <31.38%> (+38.2%) ⬆️
remoteworkitem/jira.go 75% <0%> (-25%) ⬇️
remoteworkitem/scheduler.go 53.65% <0%> (-7.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c598aee...a6ad9f0. Read the comment docs.

Copy link
Contributor

@xcoulon xcoulon left a comment

Choose a reason for hiding this comment

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

this looks good overall, but have you considered using something like go-vcr to handle the HTTP responses ? This would require you to configure/replace the default HTTP client's transport of the Kube/OS client with the one provided by the recorder, but then you may have less boilerplate code in your tests.

@ebaron
Copy link
Contributor Author

ebaron commented Feb 13, 2018

@xcoulon go-vcr sounds promising. Could I consider that as a future enhancement, since it would involve substantial changes?

@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-2

@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-3

@ebaron
Copy link
Contributor Author

ebaron commented Feb 16, 2018

@xcoulon Sorry about the broken rebase, this happened due to moving from the old "apps" API to "deployments" during development. I've squashed the commits and all seems good now.

@xcoulon
Copy link
Contributor

xcoulon commented Feb 23, 2018

@ebaron ok, I'm fine with using go-vcr later if you prefer... but please give it a try at least on 1 test to see if it helps reducing the amount of .go code.

Copy link
Contributor

@xcoulon xcoulon left a comment

Choose a reason for hiding this comment

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

PR approved

@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-4

@ebaron
Copy link
Contributor Author

ebaron commented Feb 23, 2018

@xcoulon I'll try to experiment using go-vcr shortly. I filed an issue here: openshiftio/openshift.io#2355
Thanks for approving in the meantime.

@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-5

@fabric8cd
Copy link

@ebaron snapshot fabric8-wit image is available for testing. docker pull docker.io/fabric8/fabric8-wit:SNAPSHOT-PR-1894-6

@xcoulon xcoulon merged commit 0197dec into fabric8-services:master Mar 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants