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

More integration tests #208

Merged

Conversation

corneliusweig
Copy link
Contributor

@corneliusweig corneliusweig commented Jun 6, 2019

These are based on #203 and should be merged after that one. Reviewing before #203 is merged makes also no sense :-/

The tests currently cover the happy path of all subcommands excluding krew upgrade. Upgrade is a special case because it needs two versions of a valid plugin. That will be difficult to set up and may be better in a separate PR.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 6, 2019
@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 Jun 6, 2019
@corneliusweig corneliusweig marked this pull request as ready for review June 6, 2019 23:19
@codecov-io
Copy link

codecov-io commented Jun 6, 2019

Codecov Report

Merging #208 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #208   +/-   ##
=======================================
  Coverage   53.77%   53.77%           
=======================================
  Files          13       13           
  Lines         716      716           
=======================================
  Hits          385      385           
  Misses        279      279           
  Partials       52       52

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 04288cb...287a50b. Read the comment docs.

docs/CONTRIBUTOR_GUIDE.md Outdated Show resolved Hide resolved
Missing subcommand: upgrade
0 plugins -> empty string (instead of 2 lines)
1 plugin -> 1 line (instead of 2 lines)
2 plugins -> 2 lines (instead of 3 lines)
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 10, 2019
@corneliusweig corneliusweig changed the title [WIP] More integration tests More integration tests Jun 10, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 10, 2019
cmd/krew/cmd/list.go Outdated Show resolved Hide resolved
if string(in) == "" {
return nil
}
return strings.Split(string(in), "\n")
Copy link
Member

Choose a reason for hiding this comment

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

ideally you should do strings.TrimRight(string(in)) so that you avoid taking trailing \n which almost all commands will have.

Copy link
Member

Choose a reason for hiding this comment

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

with this, you don't need the =="" check,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the =="" is still required. For krew list I need the list of results to grow by one if a plugin is installed. However, when starting from none (resulting in "\n") to one plugin ("whatever\n") would result in 1 entry each.

Copy link
Member

Choose a reason for hiding this comment

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

hmm. I'm not sure if that's accurate.

Since in this case the stdout is not a tty, we don't print the tabular output.

I expect no output or at most \n. Both of which would return []string{} (len=0).

When you install a plugin I expect this to return pluginname\n, if you split it by \n it should return []string{"pluginnname"} (len=1).

Alternatively you can also test that case as output.Contains("pluginname"), which is also just fine.

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 expect no output or at most \n. Both of which would return []string{} (len=0).

That is unfortunately not the case. If the input string is empty or "\n", it will result in []string{""}.

"ExecutedVersion",
"GitTag",
"GitCommit",
"IndexURI https://github.com/kubernetes-sigs/krew-index.git",
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we'll easily break these spaces. :)
I'm not sure if this whole thing is necessary. I currently only care about exitcode=0. :)

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 think it's worth a lot to know if something is present in the output. Do you like a regex-based assertion better?

Copy link
Member

Choose a reason for hiding this comment

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

I think anything is fine.

test/krew_test.go Outdated Show resolved Hide resolved
- clarify logic for `krew list` test
- check error case for `krew info`
- make `krew version` test more resilient against formatting changes
plugin string
shouldErr bool
}{
{
Copy link
Member

Choose a reason for hiding this comment

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

please don't put negative cases to the same test case.
they are different test cases. and these aren't unit tests. tabular tests like []struct{}{} are good for tabular unit tests. but ideally each integration test case should be a separate method testing a particular scenario workflow.

e.g. try

TestKrewInfo
TestKrewInfoInvalidPlugin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. The test cases are not split into separate test functions.

@ahmetb
Copy link
Member

ahmetb commented Jun 11, 2019

I recommend removing the WIP label so we can move forward with merging.

@corneliusweig
Copy link
Contributor Author

I recommend removing the WIP label so we can move forward with merging.

The WIP label should already have been gone for a while. At least I don't see it any longer.

@ahmetb
Copy link
Member

ahmetb commented Jun 11, 2019

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, corneliusweig

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 Jun 11, 2019
@k8s-ci-robot k8s-ci-robot merged commit 95a9ad7 into kubernetes-sigs:master Jun 11, 2019
@corneliusweig corneliusweig deleted the more-integration-tests branch June 11, 2019 22:17
ahmetb added a commit to ahmetb/krew that referenced this pull request Jun 14, 2019
Adding corneliusweig to owners. He has been consistently helping both with
krew and krew-index repositories in terms of:
- developing plugins himself
- taking a stab at krew machinery with large scale code refactors
- adding integration test suite to the project
- adding more validation and test cases
- increasing developer documentation

Some of his notable work:
- kubernetes-sigs#195
- kubernetes-sigs#183
- kubernetes-sigs#191
- kubernetes-sigs#201
- kubernetes-sigs#202
- kubernetes-sigs#203
- kubernetes-sigs#208

He is familiar with the codebase enough to officially review and approve code.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
ahmetb added a commit that referenced this pull request Jun 18, 2019
Adding corneliusweig to owners. He has been consistently helping both with
krew and krew-index repositories in terms of:
- developing plugins himself
- taking a stab at krew machinery with large scale code refactors
- adding integration test suite to the project
- adding more validation and test cases
- increasing developer documentation

Some of his notable work:
- #195
- #183
- #191
- #201
- #202
- #203
- #208

He is familiar with the codebase enough to officially review and approve code.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
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