mirror of
https://github.com/romdo/gomockctx.git
synced 2026-02-19 08:06:40 +00:00
42 lines
617 B
Go
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)
|
|
})
|
|
}
|
|
}
|