Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Add ginkgo tests for svcat get classes #2230

Merged

Conversation

carolynvs
Copy link
Contributor

This is a follow-up on #2116. I had originally only written tests for error handling cases, this fills that in to use the new pattern that @jberkhahn has set for our command tests.

@carolynvs carolynvs requested a review from jberkhahn July 24, 2018 15:23
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 24, 2018
@jberkhahn
Copy link
Contributor

This looks good. Are we keeping the old tests around? They just seem kinda weird to me because they're more like integration tests than units (they go all the way down through the pkg lib to a faked out clientset). Should we move them somewhere else? I do think we should have integration tests.

@carolynvs
Copy link
Contributor Author

carolynvs commented Jul 24, 2018

I think that they really belong in the pkg/svcat/service-catalog package as unit tests. I'll move them there and switch them to use ginkgo too for consistency. Separate PR or this one?

Expect(cmd.name).To(Equal("mysqldb"))
})
})
Describe("getAll", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

generally you don't have to test private methods, as they should be subsumed in whatever public methods use them. I would change this to test Run(), and control the different cases by modifying whether you pass in a uuid or name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's wrong with a unit test testing a single function?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not the testing a single function, it's that it's a private function - if the content of getAll was just inlined in Run, it wouldn't make sense to try to test the functionality of that block specifically, and because it's private, it kinda is just inlined.

This wouldn't be a big change, just switch the describe to "Run", and change the calls to to getAll with calls to Run with the appropriate fields filled in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment to the test about not worrying about it if it breaks. I'm not hung up on idealogical test purity that says you only test public methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would we add a test that we don't care if it breaks? And you do test private methods, but implicitly. A test for Run(), which I think we should definitely have, would be 99% the same lines of code as the tests she's written here for getAll() and a hypothetical test for get()

Expect(output).To(ContainSubstring("postgresdb"))
})
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Would also be nice to have a set of cases for when you're just getting a single class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the next PR. This change was only for getting a list of classes. 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jberkhahn
Copy link
Contributor

The ginkgo tests I added in pkg/svcat/service-catalog already do that, though (fake out the clientset and call out to it).

@carolynvs
Copy link
Contributor Author

Oh! Okay I'll compare what's there with these that we think that maybe duplicates and see if they add any new test cases or can be dropped. Expect a follow-up PR.

In the meantime, I'm fixing up the test to call Run instead of getAll

@carolynvs
Copy link
Contributor Author

@jberkhahn I've switched to testing Run vs. getAll.

@MHBauer
Copy link
Contributor

MHBauer commented Jul 26, 2018

/retest

@jeremyrickard
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 30, 2018
@jboyd01
Copy link
Contributor

jboyd01 commented Jul 30, 2018

/lgtm

@jboyd01
Copy link
Contributor

jboyd01 commented Jul 30, 2018

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jboyd01

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2018
@k8s-ci-robot k8s-ci-robot merged commit f847988 into kubernetes-retired:master Jul 30, 2018
@MHBauer MHBauer mentioned this pull request Aug 2, 2018
@carolynvs carolynvs deleted the ginkgo-tests-for-get-classes branch October 4, 2018 21:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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 Indicates that a PR is ready to be merged. LGTM1 LGTM2 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.

7 participants