[Proposal] log/logtest: Redesign 2nd edition#6464
Closed
pellared wants to merge 58 commits intoopen-telemetry:mainfrom
Closed
[Proposal] log/logtest: Redesign 2nd edition#6464pellared wants to merge 58 commits intoopen-telemetry:mainfrom
pellared wants to merge 58 commits intoopen-telemetry:mainfrom
Conversation
Closed
pellared
commented
Mar 20, 2025
| } | ||
|
|
||
| // AssertOption allows for fine grain control over how AssertEqual operates. | ||
| type AssertOption interface { |
Member
Author
There was a problem hiding this comment.
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.
pellared
commented
Mar 20, 2025
Comment on lines
+69
to
+75
| // IgnoreTimestamp disables checking if timestamps are different. | ||
| func IgnoreTimestamp() AssertOption { | ||
| return fnOption(func(cfg assertConfig) assertConfig { | ||
| cfg.ignoreTimestamp = true | ||
| return cfg | ||
| }) | ||
| } |
Member
Author
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
This was referenced Mar 21, 2025
Member
Author
|
I created sub-issues for #6341 |
This was referenced Mar 18, 2025
pellared
added a commit
that referenced
this pull request
Apr 12, 2025
pellared
added a commit
that referenced
this pull request
May 13, 2025
Fixes #6487 Fixes #6488 Towards #6341 Prior-art: #6464 Replace `AssertRecordEqual` with `AssertEqual` which accepts options and can work not only with `Record` but most importantly, whole `Recording`. 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 with `testify` 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. Here is an example of how the current tests of log bridges can be improved: - open-telemetry/opentelemetry-go-contrib#6953
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A proposal on how to fix #6341
Supersedes #6342 by addressing:
Changes:
RecordFactoryRecorder.Resultfrom[]*ScopeRecordstoRecordinget al.ScopeRecordselement.AssertEqualAssertRecordEqualwithAssertEqualwhich accepts options and can work not only withRecordbut most importantly, wholeRecordingThe 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 withtestifywe cannot force[]log.KeyValueto 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.