backend: config: Refactor TestParse function#3512
backend: config: Refactor TestParse function#3512andoriyaprashant wants to merge 9 commits intokubernetes-sigs:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: andoriyaprashant The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
skoeva
left a comment
There was a problem hiding this comment.
Thanks for looking into this issue! We can avoid duplicating code by using table-driven tests, I think it's more idiomatic in situations like this
skoeva
left a comment
There was a problem hiding this comment.
Good work, would just suggest a couple of things before approval:
- Squash all your changes (and rebases) into one atomic commit
- Adjust the PR title and commit title to the following format:
backend: config: Refactor TestParse function
skoeva
left a comment
There was a problem hiding this comment.
what issues were you having? it isn't advisable to reopen PRs because of e.g. rebase issues, is this the case? git rebase -i should be good to wrap up the changes on this branch
Summary
This PR refactors the
TestParsefunction inconfig_test.goto reduce its length and complexity. The function was previously too long and had the linter disabled using//nolint:funlenRelated Issue
Fixes #3287
Changes
TestParseinto smaller, individual test functions.//nolint:funlencomment.Test
=== RUN TestParseNoArgsNoEnv --- PASS: TestParseNoArgsNoEnv (0.00s) === RUN TestParseWithArgs --- PASS: TestParseWithArgs (0.00s) === RUN TestParseFromEnv --- PASS: TestParseFromEnv (0.00s) === RUN TestParseBothArgsAndEnv --- PASS: TestParseBothArgsAndEnv (0.00s) === RUN TestParseOidcSettingsWithoutInCluster {"level":"error","source":"F:/headlamp/backend/pkg/config/config.go","line":171,"error":"oidc-client-id, oidc-client-secret, oidc-idp-issuer-url, oidc-validator-client-id, \n\t\toidc-validator-idp-issuer-url, flags are only meant to be used in inCluster mode","time":"2025-06-24T04:42:00+05:30","message":"validating config"} --- PASS: TestParseOidcSettingsWithoutInCluster (0.00s) === RUN TestParseInvalidBaseURL {"level":"error","source":"F:/headlamp/backend/pkg/config/config.go","line":171,"error":"base-url needs to start with a '/' or be empty","time":"2025-06-24T04:42:00+05:30","message":"validating config"} --- PASS: TestParseInvalidBaseURL (0.00s) === RUN TestParseKubeconfigFromDefaultEnv --- PASS: TestParseKubeconfigFromDefaultEnv (0.00s) === RUN TestParseEnableDynamicClusters --- PASS: TestParseEnableDynamicClusters (0.00s) PASS ok github.com/kubernetes-sigs/headlamp/backend/pkg/config