-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
0 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,13 @@ package sentry | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const testDsn = "http://[email protected]/1337" | ||
|
@@ -327,88 +325,6 @@ func TestHasHubOnContextReturnsFalseIfHubIsNotThere(t *testing.T) { | |
assertEqual(t, false, HasHubOnContext(ctx)) | ||
} | ||
|
||
func TestHub_ContinueTrace(t *testing.T) { | ||
newScope := func() *Scope { | ||
return &Scope{contexts: make(map[string]Context)} | ||
} | ||
|
||
mockClient := &Client{options: ClientOptions{EnableTracing: true}} | ||
|
||
tests := map[string]struct { | ||
hub *Hub | ||
trace string | ||
baggage string | ||
expectedErr error | ||
expectedSpan bool // Whether a SpanOption is expected to be returned | ||
checkScope func(t *testing.T, scope *Scope) // Additional checks on the scope | ||
}{ | ||
"Valid trace and baggage": { | ||
hub: NewHub(mockClient, newScope()), | ||
trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", | ||
baggage: "sentry-release=1.0.0,sentry-environment=production", | ||
expectedErr: nil, | ||
expectedSpan: true, | ||
checkScope: func(t *testing.T, scope *Scope) { | ||
assert.Equal(t, "4fbfb1b884c8532962a3c0b7b834428e", scope.propagationContext.TraceID.String()) | ||
}, | ||
}, | ||
"Invalid trace": { | ||
hub: NewHub(mockClient, newScope()), | ||
trace: "invalid", | ||
baggage: "sentry-release=1.0.0,sentry-environment=production", | ||
expectedErr: nil, | ||
expectedSpan: true, | ||
checkScope: func(t *testing.T, scope *Scope) { | ||
assert.NotEmpty(t, scope.propagationContext.TraceID.String()) | ||
}, | ||
}, | ||
"Invalid baggage": { | ||
hub: NewHub(mockClient, newScope()), | ||
trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", | ||
baggage: "invalid_baggage", | ||
expectedErr: errors.New("invalid baggage list-member: \"invalid_baggage\""), | ||
expectedSpan: false, | ||
checkScope: func(t *testing.T, scope *Scope) { | ||
assert.Equal(t, "00000000000000000000000000000000", scope.propagationContext.TraceID.String()) | ||
}, | ||
}, | ||
"Tracing not enabled": { | ||
hub: NewHub(&Client{options: ClientOptions{EnableTracing: false}}, newScope()), | ||
trace: "4fbfb1b884c8532962a3c0b7b834428e-a9f442f9330b4e09", | ||
baggage: "sentry-release=1.0.0,sentry-environment=production", | ||
expectedErr: nil, | ||
expectedSpan: false, | ||
checkScope: func(t *testing.T, scope *Scope) { | ||
assert.Equal(t, "4fbfb1b884c8532962a3c0b7b834428e", scope.propagationContext.TraceID.String()) | ||
assert.Contains(t, scope.contexts, "trace") | ||
}, | ||
}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
opt, err := tt.hub.ContinueTrace(tt.trace, tt.baggage) | ||
|
||
if tt.expectedErr != nil { | ||
assert.Error(t, err, "expected error, got nil") | ||
assert.Equal(t, tt.expectedErr.Error(), err.Error()) | ||
} else { | ||
assert.NoError(t, err, "expected no error, got one") | ||
} | ||
|
||
// Check for expected SpanOption | ||
if tt.expectedSpan { | ||
assert.NotNil(t, opt, "expected SpanOption, got nil") | ||
} else { | ||
assert.Nil(t, opt, "expected no SpanOption, got one") | ||
} | ||
|
||
// Additional checks on the scope | ||
tt.checkScope(t, tt.hub.Scope()) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetTraceparent(t *testing.T) { | ||
tests := map[string]struct { | ||
hub *Hub | ||
|