-
Notifications
You must be signed in to change notification settings - Fork 162
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
Mock log.Fatalf calls and add test suite #2437
Conversation
Co-authored-by: Matt Moore <[email protected]>
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.
@joshua-bone: 0 warnings.
In response to this:
/lint
What this PR does, why we need it:
- Since log.Fatalf calls are untestable, this PR adds a layer of abstraction and a simple test mock.
- This PR also adds a complete test suite for the functions in utils.go.
- Increases config-generator test coverage from ~13% to 19.6%.
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.
Hi @joshua-bone. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
/ok-to-test |
The following is the coverage report on the affected files.
|
@joshua-bone: The following test failed, say
Full PR test history. Your PR dashboard. 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. |
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestMain(m *testing.M) { |
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?
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.
TestMain does setup only once for the package, not for each individual test as I believed. See this discussion: golang/go#27927
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.
oh, ha forgot about that, I thought it was a test called Main... dur
"Since log.Fatalf calls are untestable, this PR adds a layer of abstraction and a simple test mock." Won't they still cause the test to fail? |
The SetupForTesting() function replaces the logFatalf function with a mock function that simply increments a global counter variable without causing the program to exit. |
Correct, but why is this an improvement? In either case, the test correctly
fails.
…On Thu, Sep 17, 2020 at 10:30 AM Joshua Bone ***@***.***> wrote:
"Since log.Fatalf calls are untestable, this PR adds a layer of
abstraction and a simple test mock."
Won't they still cause the test to fail?
The SetupForTesting() function replaces the logFatalf function with a mock
function that simply increments a global counter variable without causing
the program to exit.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2437 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYVGCRFSH7UQ7OIIROS5MDSGJBSNANCNFSM4RQXA2SQ>
.
|
There are many cases where I want to verify that an input will cause a failure condition. In those cases I want the code to fail but the test to succeed. |
Ah, thanks!
…On Thu, Sep 17, 2020 at 10:35 AM Joshua Bone ***@***.***> wrote:
Correct, but why is this an improvement? In either case, the test correctly
fails.
There are many cases where I want to verify that an input will cause a
failure condition. In those cases I want the code to fail but the test to
succeed.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2437 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYVGCQLHKUS2TTZ3YSG2QLSGJCHZANCNFSM4RQXA2SQ>
.
|
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: coryrc, joshua-bone 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 |
/lint
What this PR does, why we need it: