Skip to content
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

[ForReview] Refactor otelzap tests #6839

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

pellared
Copy link
Member

@pellared pellared commented Feb 25, 2025

Reuse open-telemetry/opentelemetry-go#6342

Original assertion failures when I break 2 places:

--- FAIL: TestCore (0.00s)
    --- FAIL: TestCore/WithMultiple (0.00s)
        core_test.go:126: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:126
                Error:          Not equal: 
                                expected: 3
                                actual  : 2
                Test:           TestCore/WithMultiple
        core_test.go:130: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:130
                                                        /home/ropajak/go/pkg/mod/go.opentelemetry.io/otel/[email protected]/record.go:117
                                                        /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:129
                Error:          Not equal: 
                                expected: "test2"
                                actual  : "test3"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -test2
                                +test3
                Test:           TestCore/WithMultiple
        core_test.go:131: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:131
                                                        /home/ropajak/go/pkg/mod/go.opentelemetry.io/otel/[email protected]/record.go:117
                                                        /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:129
                Error:          Not equal: 
                                expected: "value2"
                                actual  : "value3"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -value2
                                +value3
                Test:           TestCore/WithMultiple
        core_test.go:132: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:132
                                                        /home/ropajak/go/pkg/mod/go.opentelemetry.io/otel/[email protected]/record.go:117
                                                        /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:129
                Error:          Not equal: 
                                expected: "value2"
                                actual  : "value3"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -value2
                                +value3
                Test:           TestCore/WithMultiple
--- FAIL: TestCoreWithCaller (0.00s)
    core_test.go:185: 
                Error Trace:    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:185
                                                        /home/ropajak/go/pkg/mod/go.opentelemetry.io/otel/[email protected]/record.go:117
                                                        /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:176
                Error:          Not equal: 
                                expected: "go.opentelemetry.io/BAD/bridges/otelzap"
                                actual  : "go.opentelemetry.io/contrib/bridges/otelzap"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -go.opentelemetry.io/BAD/bridges/otelzap
                                +go.opentelemetry.io/contrib/bridges/otelzap
                Test:           TestCoreWithCaller
FAIL
exit status 1
FAIL    go.opentelemetry.io/contrib/bridges/otelzap     0.006s

Here is how assertion failures looks after the changes:

-- FAIL: TestCore (0.00s)
   --- FAIL: TestCore/WithMultiple (0.00s)
        /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:165: recording mismatch (-want +got):
              logtest.Recording{
              	{Name: "name"}: {
              		{
              			... // 2 ignored and 3 identical fields
              			SeverityText: "info",
              			Body:         s"log message",
              			Attributes: []log.KeyValue(Inverse(cmpopts.SortSlices, []log.KeyValue{
            - 				s"a:b",
              				s"fizz:buzz",
              				s"foo:bar",
              			})),
              		},
              	},
              }
            
--- FAIL: TestCoreWithCaller (0.00s)
    /home/ropajak/repos/opentelemetry-go-contrib/bridges/otelzap/core_test.go:257: "code.namespace" attribute has bad value, got = go.opentelemetry.io/contrib/bridges/otelzap, want = "go.opentelemetry.io/BAD/bridges/otelzap"

Personally, I also find the tests more readable and easier to maintain. For instance, check the current version of WithMultiple.

@scorpionknifes, @dmathieu, can you take a look and give feedback if you think if it is an improvement?

@pellared pellared requested a review from a team as a code owner February 25, 2025 12:38
@pellared pellared changed the title [ForReview] Refactor otelzap tests [ForReview] [DoNotMerge] Refactor otelzap tests Feb 25, 2025
@pellared pellared added the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Feb 25, 2025
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.1%. Comparing base (89cbae1) to head (a114036).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #6839   +/-   ##
=====================================
  Coverage   76.1%   76.1%           
=====================================
  Files        219     219           
  Lines      21313   21313           
=====================================
  Hits       16221   16221           
  Misses      4531    4531           
  Partials     561     561           

@pellared
Copy link
Member Author

@khushijain21, can you also take a look as a code owner?

@pellared pellared marked this pull request as draft February 26, 2025 16:50
@pellared pellared changed the title [ForReview] [DoNotMerge] Refactor otelzap tests [ForReview] Refactor otelzap tests Feb 26, 2025
@khushijain21
Copy link
Contributor

The new logtest design looks great! and I agree it makes it more readable. LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants