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

Add cmd unittest #2075

Merged
merged 12 commits into from
Jun 21, 2018
Merged

Conversation

artmello
Copy link
Contributor

Based on the work done by @carolynvs at #2049 this PR add unit tests for get and describe commands.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 28, 2018
@artmello
Copy link
Contributor Author

@carolynvs I don't think I can set a reviewer to this, but could you take a look whenever you have some time?

@MHBauer MHBauer requested a review from carolynvs May 29, 2018 07:04
@artmello artmello changed the title WIP: Add cmd unittest Add cmd unittest Jun 8, 2018
Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review, and thank you for tackling adding these tests! 💖

name: "describe non existing binding",
fakeBindings: []string{},
bindingName: "mybinding",
expected: "unable to get binding '" + namespace + ".mybinding': servicebindings.servicecatalog.k8s.io \"mybinding\" not found",
Copy link
Contributor

@carolynvs carolynvs Jun 14, 2018

Choose a reason for hiding this comment

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

Doing an exact full string match is going to make these tests difficult to maintain going forward. We have another set of tests that do full output comparisons on stdout/stderr for the cli.

I recommend that for these tests, we do a strings.Contains check instead, and only specify a small portion of the expected output. That will give us enough to check for error messages, without needing to regularly update these tests as the output changes.

So you could change this to just check for the portion of the error message that is controlled by the CLI: unable to get binding ns/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.

I agree and latest commit should make the tests work as suggested.

name: "describe existing binding",
fakeBindings: []string{"mybinding"},
bindingName: "mybinding",
expected: " Name: mybinding \n Namespace: " + namespace + " \n Status: \n Secret: \n Instance: \n\nParameters:\n No parameters defined\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

For successful cases, I suggest not looking for an expected string and just relying on wantError: false since the full cli output is adequately tested elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, in that case I changed "expected" for "expectedError" and moved the check for only when wantError is true.

wantError: false,
},
{
name: "get all existing bindings with json output format",
Copy link
Contributor

Choose a reason for hiding this comment

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

These successful --output test cases are already covered by other tests, so we can remove the expectation on their full output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed them on latest commit

bindingName: "mybinding",
outputFormat: "unknown",
expected: "",
wantError: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

haha, I would have expected this to be wantError: true! You may have found a bug. :-) We can follow up on that after this PR is merged. 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it is necessary to open an issue to track this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah a bug is a good idea. Feel free to make one yourself and reference this test, or I will do that later today.

- Do not check for full output string match in case of success, since this is already tested at other places
- Check if, in case of errors, output contains relevant data
@artmello
Copy link
Contributor Author

Thanks a lot for your review @carolynvs, hopefully all issues are addressed with latest commit. Let me know if you think it should be improved some other way.

Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks for these changes! It is going to make it much easier in the future for us to flag changes in this area of code for new contributors! 💖

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

oops! I forgot that you need a rebase before we can merge, now that #2049 has been merged. I'll put a LGTM on this once that's in.

@carolynvs carolynvs added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed LGTM1 labels Jun 15, 2018
@MHBauer
Copy link
Contributor

MHBauer commented Jun 15, 2018

FYI, @artmello can set reviewers with /cc command and approvers with /assign.
I want to say this works throughout kubernetes-org repos, but it's hit or miss depending on what's been enabled. I think those two are pretty default commands available.

@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot k8s-ci-robot removed lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 15, 2018
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 15, 2018
@carolynvs carolynvs removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2018
@carolynvs
Copy link
Contributor

LGTM, and this time I mean it! 😊

Copy link
Contributor

@arschles arschles left a comment

Choose a reason for hiding this comment

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

LGTM

@arschles arschles added the LGTM2 label Jun 21, 2018
@arschles arschles merged commit 572b849 into kubernetes-retired:master Jun 21, 2018
kikisdeliveryservice pushed a commit to kikisdeliveryservice/service-catalog that referenced this pull request Jun 29, 2018
* Add svcat output tests for waitable commands

* bind
* unbind
* provision
* deprovision

* Fix writing deleted bindings when --wait isn't set

* don't use glog, it's not test friendly

* Fix handling when not all binding deletes fail

* Return the proper exit code when a failure occurs
* Print the names of any bindings that did delete sucessfully

* Wrap errors to preserve type checking later

* Make error messages consistent with latest version of cobra

* Don't prefix with 'Error:' for ungrouped error messages
* Don't capitalize the first letter in the messages

* appeasing the boilerplate gods

* Fix testdata so that its not racey

* Update test output with recently merged changes from master

* Add unittest for srvcat get and describe command

* Update tests for describe and get svcat commands

- Do not check for full output string match in case of success, since this is already tested at other places
- Check if, in case of errors, output contains relevant data
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

6 participants