-
Notifications
You must be signed in to change notification settings - Fork 448
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
Replaced reflect.DeepEqual with cmp.Diff in Go tests #2281
Replaced reflect.DeepEqual with cmp.Diff in Go tests #2281
Conversation
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.
Could you apply the same approach the same as my comment to other places?
} else if !reflect.DeepEqual(expectedRunSpec, actualRunSpec) { | ||
t.Errorf("Case: %v failed. Expected %v\n got %v", tc.testDescription, expectedRunSpec.Object, actualRunSpec.Object) | ||
} else if diff := cmp.Diff(expectedRunSpec.Object, actualRunSpec.Object); diff != "" { | ||
t.Errorf("Case: %v failed. Diff (-expected, +actual):\n%s", tc.testDescription, diff) |
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.
We must define errors, and compare expected and wanted errors and values.
Define errors:
katib/pkg/util/v1beta1/katibconfig/config.go
Lines 38 to 42 in 6fb9157
var ( | |
ErrKatibConfigNil = fmt.Errorf("failed to parse katib-config.yaml in ConfigMap: %s", consts.KatibConfigMapName) | |
ErrInvalidGVKFormat = errors.New("invalid GroupVersionKinds") | |
ErrTrialResourcesAreEmpty = errors.New("trialResources are empty") | |
) |
Compare Errors:
katib/pkg/util/v1beta1/katibconfig/config_test.go
Lines 72 to 74 in 6fb9157
if diff := cmp.Diff(tc.wantError, err, cmpopts.EquateErrors()); len(diff) != 0 { | |
t.Errorf("Unexpected error from TrialResourcesToGVKs (-want,+got):\n%s", diff) | |
} |
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.
Sounds good. I am creating a separate PR given that file-metricscollector_test.go has already been updated in #2274.
6fb9157
to
6f372f6
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tariq-hasan 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 |
What this PR does / why we need it: This PR replaces reflect.DeepEqual with cmp.Diff in all the tests.
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 #2268
Checklist: