-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add required tests for internal/flag
#15220
Conversation
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
oldCommandLine := goflag.CommandLine | ||
defer func() { | ||
goflag.CommandLine = oldCommandLine | ||
}() | ||
|
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 do we need to mutate the global flagset to do these tests? from my reading we should be able to do our assertions with testFlagSet
directly
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.
The function PreventGlogVFlagFromClobberingVersionFlagShorthand
uses f := goflag.Lookup("v")
, so we need to register v
flag in goflag.CommandLine
for this.
} | ||
|
||
func TestParse(t *testing.T) { | ||
oldCommandLine := goflag.CommandLine |
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.
same comment here
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.
The function Parse
has fs.AddGoFlagSet(goflag.CommandLine)
, to test this we first register a testFlag in goflag.CommandLine
, then to check if this was called, we use testFlagSet.Lookup
. Please let me know if I am missing something here.
assert.True(t, isProvided) | ||
} | ||
|
||
func TestFilterTestFlags(t *testing.T) { |
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.
i'm not sure we need this, as we exercise this function in a bunch of end-to-end tests implicitly (cc @rohit-nayak-ps)
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.
I think the aim here is to increase unit test coverage, so it is fine to add these, especially since we don't yet have the tooling to incorporate the test coverage from e2e tests into our Code Coverage CI workflow.
assert.Equal(t, expectedTestFlags, testFlags) | ||
} | ||
|
||
func TestParseFlagsForTest(t *testing.T) { |
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.
same about not needing this test
go/internal/flag/flag_test.go
Outdated
} | ||
|
||
func TestIsZeroValue(t *testing.T) { | ||
oldCommandLine := goflag.CommandLine |
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.
again, we don't need to mutate global state for this test
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.
Alternatively, created new FlagSet
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15220 +/- ##
==========================================
- Coverage 67.34% 65.48% -1.87%
==========================================
Files 1560 1562 +2
Lines 192571 193911 +1340
==========================================
- Hits 129695 126982 -2713
- Misses 62876 66929 +4053 ☔ View full report in Codecov by Sentry. |
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.
looking good! just a few minor things
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
@ajm188 can you please review? |
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Description
This PR adds required tests for
go/internal/flag
.Related Issue(s)
Fixes part of #14931
Checklist
Deployment Notes