-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathbuilder_test.go
More file actions
26 lines (22 loc) 路 735 Bytes
/
Copy pathbuilder_test.go
File metadata and controls
26 lines (22 loc) 路 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package oops
import (
"context"
"testing"
)
type stringerContextKey int
func (k stringerContextKey) String() string { return "request_id" }
func TestWithContextPreservesStringerKeyIdentity(t *testing.T) {
t.Parallel()
key := stringerContextKey(1)
ctx := context.WithValue(context.Background(), key, "typed value")
// A string key with the same display name must not shadow the typed key.
ctx = context.WithValue(ctx, "request_id", "string value") //nolint:staticcheck,revive
wrapped := WithContext(ctx, key).Errorf("failed")
err, ok := wrapped.(OopsError)
if !ok {
t.Fatalf("unexpected error type: %T", wrapped)
}
if got := err.context["request_id"]; got != "typed value" {
t.Fatalf("context value = %v", got)
}
}