-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Proposal] [DoNotMerge] log/logtest: Redesign 2nd edition #6464
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
// AssertOption allows for fine grain control over how AssertEqual operates. | ||
type AssertOption 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.
SIG meeting: There was a proposal by @MrAlias to add an option to add additional failure message.
It would be better to add each option as a separate PR.
// IgnoreTimestamp disables checking if timestamps are different. | ||
func IgnoreTimestamp() AssertOption { | ||
return fnOption(func(cfg assertConfig) assertConfig { | ||
cfg.ignoreTimestamp = true | ||
return cfg | ||
}) | ||
} |
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.
SIG meeting: There was a proposal by @MrAlias to add some more generic function that would transform the Record
(or any type?) before comparing. This would provide more flexibility e.g.
logtest.AssertEqual(t, want, got, logtest.Mutate(func (r logtest.Record) logtest.Record {
r.Timestamp = time.Time{}
return r
}))
Maybe https://pkg.go.dev/github.com/google/go-cmp/cmp#Transformer could used to achieve it.
It would be better to add each option as a separate PR.
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 created sub-issues for #6341 |
A proposal on how to fix #6341
Supersedes #6342 by addressing:
Changes:
RecordFactory
Recorder.Result
from[]*ScopeRecords
toRecording
et al.ScopeRecords
element.AssertEqual
AssertRecordEqual
withAssertEqual
which accepts options and can work not only withRecord
but most importantly, wholeRecording
The changes between the previous approach are inspired by the design of https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest. Thanks to it we continue to use the "assert" pattern, but are not impacted by downsides of
testify
. The main issue is that withtestify
we cannot force[]log.KeyValue
to sort slices before comparing (unordered collection equality). This can make the tests too much "white-boxed" and can easy break during refactoring. Moreover, empty and nil slices are seen not equal which in this case is not relevant. Ignoring timestamps would also mean changing the "got". More: #6342 (comment).Here is an example of how the current tests of log bridges can be improved:
I will split this into a few PRs to make reviews easier.
Still, I think that this PR is necessary in order to validate and review the new design before going further.
I added
[Proposal] [DoNotMerge]
prefix to make it clear that I do not intend to merge this PR.