Skip to content
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

🌱 (chore): prevent variable shadowing in DecodePluginConfig test to ensure accurate assertion #4711

Conversation

kersten
Copy link
Contributor

@kersten kersten commented Mar 28, 2025

🌱 (chore): DecodePluginConfig test variable reuse

This PR fixes potential shadowing in table-driven tests by renaming pluginCfg to decodedPluginCfg. This avoids confusion between the decoded result and the expected struct, ensuring the assertions are valid and that Gomega receives the correct references.

This improves test clarity and avoids subtle bugs due to variable reuse within closures.

@k8s-ci-robot
Copy link
Contributor

Hi @kersten. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 28, 2025
var pluginCfg PluginConfig
err := c0.DecodePluginConfig(key, &pluginCfg)
var decodedPluginCfg PluginConfig
err := c0.DecodePluginConfig(key, &decodedPluginCfg)
Expect(err).To(HaveOccurred())
Expect(errors.As(err, &config.PluginKeyNotFoundError{})).To(BeTrue())
Copy link
Contributor

@nunnatsa nunnatsa Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Consider using the gomega's MatchError matcher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nunnatsa You're absolutely right - this should be addressed. I'd prefer to keep it out of scope for this PR though, as it's unrelated to the main change. There are a few places in the codebase where errors.As is used in the tests, so it would make sense to handle all of them together in a separate PR. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've open another PR for it here: #4723

var pluginCfg PluginConfig
err := c1.DecodePluginConfig("plugin-y", &pluginCfg)
var decodedPluginCfg PluginConfig
err := c1.DecodePluginConfig("plugin-y", &decodedPluginCfg)
Expect(err).To(HaveOccurred())
Expect(errors.As(err, &config.PluginKeyNotFoundError{})).To(BeTrue())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@kersten
Copy link
Contributor Author

kersten commented Mar 31, 2025

/test macos-latest

@k8s-ci-robot
Copy link
Contributor

@kersten: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test macos-latest

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.

@kersten kersten force-pushed the fix/decodepluginconfig-test-var-clash branch from 26c8f93 to 82fdfd7 Compare March 31, 2025 12:59
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 31, 2025
@k8s-ci-robot
Copy link
Contributor

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-sigs/prow repository.

@kersten kersten closed this Mar 31, 2025
@kersten kersten force-pushed the fix/decodepluginconfig-test-var-clash branch from 82fdfd7 to 4fe3c28 Compare March 31, 2025 13:07
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kersten

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 31, 2025
@kersten kersten deleted the fix/decodepluginconfig-test-var-clash branch March 31, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants