mirror of
https://github.com/romdo/gomockctx.git
synced 2026-02-19 08:06:40 +00:00
feat: add ID function
This commit is contained in:
41
gomockctx_test.go
Normal file
41
gomockctx_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package gomockctx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
ctx: nil,
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "without ID",
|
||||
ctx: context.Background(),
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "with ID",
|
||||
ctx: context.WithValue(
|
||||
context.Background(), ctxKey, contextValue("xI2UWC8MvdYcU22B"),
|
||||
),
|
||||
want: "xI2UWC8MvdYcU22B",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ID(tt.ctx)
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user