-
Notifications
You must be signed in to change notification settings - Fork 19
Add DryCLI status comparison #329
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 DryCLI status comparison #329
Conversation
331c86f
to
b9fe98d
Compare
pkg/dryrun/dryrun_utils.go
Outdated
isStatusMatch := compareStatusObj(cmd, true, "", inputStatus, resultStatus) | ||
|
||
if isStatusMatch { | ||
cmd.Println(successColor("\033[1m Expected status matches the actual status \033[0m")) |
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.
bold
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.
If we'll have terminal escapes for bold, I wonder if we should just "manually" do the terminal escapes for the colors ourselves, as opposed to using that library. How much trouble do you think that would it be?
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.
Let me try I don't think it is big deal
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.
Fixed Could you check
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 that's looking good. What do you think about a --no-colors
option that would turn off those escapes?
b9fe98d
to
3cfd7ad
Compare
/cc @JustinKuli |
3cfd7ad
to
2d3a7e6
Compare
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.
Sorry for the many small comments. Overall this looks really great.
I personally like the colors, but I feel like it's common to give a --no-color
option. Especially if this is a tool used in someone's CI, it can be a headache to look at the output with a bunch of terminal escape codes.
I think the exit code of the CLI is still just whether the result is compliant or not... I think we'd want to adjust that so that if the user provided a desired status, the exit code is zero if the status matches.
pkg/dryrun/cmd.go
Outdated
|
||
cmd.Flags().StringVarP( | ||
&d.configStatus, | ||
"config-status", |
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.
What do you think of "desired-status"? Would that be more clear?
I just worry that "config-status" makes it sound like it configures some piece of the status somehow.
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.
lovely
pkg/dryrun/dryrun_utils.go
Outdated
isStatusMatch := compareStatusObj(cmd, true, "", inputStatus, resultStatus) | ||
|
||
if isStatusMatch { | ||
cmd.Println(successColor("\033[1m Expected status matches the actual status \033[0m")) |
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.
If we'll have terminal escapes for bold, I wonder if we should just "manually" do the terminal escapes for the colors ourselves, as opposed to using that library. How much trouble do you think that would it be?
pkg/dryrun/dryrun_utils.go
Outdated
} | ||
|
||
switch typedV[0].(type) { | ||
case map[interface{}]interface{}, map[string]interface{}: |
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.
Isn't map[string]interface{}
a sub-case of map[interface{}]interface{}
? Is it necessary to make it a specific case?
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 seems like other pieces here want to only deal with map[string]interface
. So I think that could be made a case
on its own, and then if the next case was map[interface{}]interface{}
, that would catch the errors all together. Might be cleaner (assuming it actually works like that).
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.
Sorry, I don’t understand why these are separated—the code would be duplicated. Could you suggest an alternative implementation?
pkg/dryrun/dryrun_utils.go
Outdated
|
||
mapObj, ok := convertMapStringKey(obj).(map[string]interface{}) | ||
if !ok { | ||
failedParsePrint(cmd, path) |
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 we can consider it not a match if we fail to parse something. Warnings are too likely to be ignored in my opinion.
pkg/dryrun/dryrun_utils.go
Outdated
} | ||
|
||
func successMatchArrayPrint(cmd *cobra.Command, path string) { | ||
cmd.Println(successColor(fmt.Sprintf("%s is founded", path))) |
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.
cmd.Println(successColor(fmt.Sprintf("%s is founded", path))) | |
cmd.Println(successColor(fmt.Sprintf("%s matches", path))) |
I'm worried this message is very repetitive. Maybe it shouldn't be printed at all?
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.
should we remove
if !allMatch {
errorMatchArrayPrint(cmd, path)
isStatusMatch = false
}
This case print too?
da61bb8
to
6c23b46
Compare
pkg/dryrun/dryrun_utils.go
Outdated
isStatusMatch := compareStatusObj(cmd, true, "", inputStatus, resultStatus) | ||
|
||
if isStatusMatch { | ||
cmd.Println(successColor("\033[1m Expected status matches the actual status \033[0m")) |
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 that's looking good. What do you think about a --no-colors
option that would turn off those escapes?
dbc8f98
to
e25fa04
Compare
Ref: https://issues.redhat.com/browse/ACM-17517 Signed-off-by: yiraeChristineKim <[email protected]>
e25fa04
to
69f9424
Compare
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! Thanks
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JustinKuli, yiraeChristineKim 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 |
bf7ec7d
into
open-cluster-management-io:main
Ref: https://issues.redhat.com/browse/ACM-17517