Files
gomockctx/gomockctx_test.go
2022-02-14 18:05:16 +00:00

42 lines
617 B
Go

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)
})
}
}