feat: add ID function

This commit is contained in:
2022-02-14 18:05:16 +00:00
parent 7b743b7805
commit 4e2cdc6ec2
4 changed files with 112 additions and 35 deletions

41
gomockctx_test.go Normal file
View 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)
})
}
}