-
Notifications
You must be signed in to change notification settings - Fork 107
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
community: cleanup code, reduce complexity, add make targets #368
base: main
Are you sure you want to change the base?
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ab42c5f
to
4471b16
Compare
Based on PR kubevirt/community#368 where new make targets test and lint are introduced we are adding new presubmit jobs that execute them. Signed-off-by: Daniel Hiller <[email protected]>
Based on PR kubevirt/community#368 where new make targets test, lint and coverage are introduced we are adding new presubmit jobs that execute them. Signed-off-by: Daniel Hiller <[email protected]>
/cc @EdDev for wg-code-quality |
@aburdenthehand: GitHub didn't allow me to request PR reviews from the following users: for. Note that only kubevirt members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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-sigs/prow repository. |
"testing" | ||
) | ||
|
||
func Test_validateGroups(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.
Is the _
convention? I would expect to see TestValidateGroups
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.
Hm, good q - I believe that was an autogenerated test func name that I didn't really look at.
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.
@xpivarc I investigated a bit - reason for this weird name is that Goland has auto-generated the func name for the non-exported func that is tested.
Now if I rename the func as you requested the IDE will not find the tested func anymore.
Now my q is: does it matter that much? I'd rather expect the test func name to be as close to the name of the func it tests. WDYT?
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.
Well that is weird, see https://go.dev/doc/code#Testing where TestXXX
should work. I won't insist but my eye found it weird.
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 agree that for exported functions it should be as you said, however for non-exported functions whose name is starting with a lowercase letter the usage of an underscore might be more obvious.
Compare
func DoFuncExported() {}
func TestDoFuncExported() {}
to
func doFuncNonExported() {}
func Test_doFuncNonExported() {}
where the latter is the matching case 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.
And again - this is just to help the IDE to find the test for the func and the func for the test func.
/cc |
Makefile
Outdated
go test ./... -coverprofile=/tmp/coverage.out | ||
covreport -i /tmp/coverage.out -o ${COVERAGE_OUTPUT_PATH} | ||
|
||
install-metrics-binaries: |
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.
nit - Any reason to have another target with an unrelated name for installing a linting tool?
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.
probably over-engineering :)
Makefile
Outdated
covreport -i /tmp/coverage.out -o ${COVERAGE_OUTPUT_PATH} | ||
|
||
install-metrics-binaries: | ||
if ! command -V golangci-lint; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin ${GOLANGCI_LINT_VERSION} ; fi |
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.
nit - It would be nicer to install this into a local bin to avoid changing the users version
.golangci.yaml
Outdated
- gocyclo | ||
linters-settings: | ||
gocyclo: | ||
min-complexity: 10 |
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.
Missing new line
Adds a make target `lint` that will be used to run enabled linters, which are configured via .golangci.yaml . Initially only the default linters are enabled, additionally the gocyclo linter with ccn > 10. Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Adds a `test` target to the Makefile that executes the go tests. Signed-off-by: Daniel Hiller <[email protected]>
Adds unit tests for sig validation as precondition of refactoring. Signed-off-by: Daniel Hiller <[email protected]>
* reduce complexity by converting all groups into a single map * replace if then with early return * extract validateLeads, use that in two places Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
Signed-off-by: Daniel Hiller <[email protected]>
@lyarwood thank you for the review and apologies for the long wait time. I have addressed your comments, but since a rebase happened some linting errors had entered the code base again. I have fixed these now. PTAL, thank you! 🙏 |
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.
/lgtm
🏓 @aburdenthehand 🙂 |
@xpivarc - you happy? |
What this PR does / why we need it:
Reduces complexity in:
validators/cmd/sigs-validator
generators/cmd/devstats
Adds make targets:
lint
- will run golangci-lint, additionally gocyclo with> 10
test
- will run go tests/kind cleanup
/wg code-quality
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer: