-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Istioctl Go tests for get/create/update/delete #5734
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
Conversation
Codecov Report
@@ Coverage Diff @@
## release-0.8 #5734 +/- ##
=============================================
- Coverage 73% 72% -1%
=============================================
Files 322 330 +8
Lines 27576 28713 +1137
=============================================
+ Hits 20027 20442 +415
- Misses 6754 7441 +687
- Partials 795 830 +35
Continue to review full report at Codecov.
|
} | ||
return nil | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, it would be good to invoke the subcommand via Execute
to verify we've setup PersistentPreRunE correct. e.g.
rootCmd.SetArgs(c.args)
rootCmd.Execute()
} | ||
|
||
// captureOutput invokes f capturing the output sent to stderr and stdout | ||
func captureOutput(f func() error) (string, string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we capture cobra output more directly using the SetOutput
helper function?
var out bytes.Buffer
rootCmd.SetOutput(out)
@ayj I am now using Execute() to run and SetOutput() to obtain stderr messages. I am still using os.Stdout redirection to capture normal output because istioctl writes directly to os.Stdout and I could not find a way to use Cobra to capture that output. |
/retest |
capturedOutput := <-outChannel | ||
|
||
return capturedOutput, errF | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick google search for this pattern indicates you may want to start the goroutine before invoking the test function (see here). The golang testing example code might be a good reference (see https://golang.org/src/testing/example.go#L60).
Also, I'm not sure how capturing stdio will work if tests are later run in parallel. It might be good to convert istioctl functions over to use explicit printf
and fatalf
interface functions like Mixer and Galley code. We could then redirect that to cobra.Print or provide our own fake to explicit capture all stdout and stderr.
|
||
stdOutput, fErr := captureStdout( | ||
func() error { | ||
rootCmd.SetArgs(c.args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is rootCmd.SetArgs(c.args)
called twice?
/lgtm |
/test e2e-pilot |
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ayj, esnible Assign the PR to them by writing 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 |
@esnible: PR needs rebase. 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. |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@esnible: The following tests failed, say
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. I understand the commands that are listed here. |
@ayj Now that Master is open I retargeted this for 1.0. cla/google is failing and the presubmit can't auto-merge. Is it reasonable to just abandon this and cut and paste the changes into a fresh PR? |
This creates tests on the output of
istioctl get x
(alsodelete
and a bit ofcreate
/update
.)The implementation uses memory.Make() to create a model.ConfigStore and uses it as a mock.
This doesn't fix any issues but I wanted to get it in place so that #5668 , #5538 , and #5502 will have test cases and code coverage.