-
Notifications
You must be signed in to change notification settings - Fork 65
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
Refactor commands to take a viper instance #1200
base: main
Are you sure you want to change the base?
Conversation
Instead of relying on a global instance, the commands should instead have viper injected. This will make testing easier. Signed-off-by: Brad P. Crochet <brad@redhat.com>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bcrochet 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 |
Replaces #958 |
from change #1200: |
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.
Looks fine overall. Mostly nits, except the ResultSubmitter{}.Submit
interface definition change.
@@ -29,7 +28,7 @@ type ResultWriter interface { | |||
|
|||
// ResultSubmitter defines methods associated with submitting results to Red HAt. | |||
type ResultSubmitter interface { | |||
Submit(context.Context) error | |||
Submit(context.Context, string) error |
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.
Can we either:
- Name the parameters here, such that it's clear what the string value should be without having to look at when it's called, or
- Update the documentation such that it's clear?
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.
It could be a type alias to make it clearer. TBH, we shouldn't even be exporting interfaces in the first place.
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.
A type alias isn't strictly necessary. Something like this should be plenty:
Submit(context.Context, string) error | |
Submit(ctx context.Context, pyxisEnv string) error |
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 was confused by this as well, it took me till the end of the PR to understand that this was pyxisEnv
.
func checkContainerPreRunE(cmd *cobra.Command, args []string) error { | ||
certificationProjectID := viper.GetString("certification_project_id") | ||
validatedCertificationProjectID, err := validateCertificationProjectID(certificationProjectID) | ||
if err != nil { | ||
return err | ||
} | ||
if validatedCertificationProjectID != certificationProjectID { | ||
viper.Set("certification_project_id", validatedCertificationProjectID) | ||
} | ||
return nil | ||
} | ||
|
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.
Extraneous?
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.
Might be vestigial from an earlier revision, given the age of this patch.
I'll check it out.
@@ -145,24 +152,24 @@ var _ = Describe("Check Container Command", func() { | |||
Entry("index manifest, invalid platform", "index", "none", HaveOccurred(), true), | |||
) | |||
|
|||
Context("When validating check container arguments and flags", func() { | |||
When("validating check container arguments and flags", func() { |
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.
Non-blocking: Why did you switch from context
to when
, is there some benefit? I'm fine with the change, but just want to understand the driving factor.
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.
It does the same thing, but "reads" better. In both the code and the output when a test fails.
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. |
Instead of relying on a global instance, the commands should instead have viper injected. This will make testing easier.