mirror of
https://github.com/romdo/gomockctx.git
synced 2026-02-19 08:06:40 +00:00
refactor: Deprecate Is() in favor of Eq() which behaves the same
This commit is contained in:
18
gomockctx.go
18
gomockctx.go
@@ -49,16 +49,28 @@ func New(parent context.Context) context.Context {
|
|||||||
return context.WithValue(parent, ctxKey, newCtxID())
|
return context.WithValue(parent, ctxKey, newCtxID())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is accepts a context with a gomockctx ID value (as returned from New), and
|
// Eq accepts a context with a gomockctx ID value (as returned from New), and
|
||||||
// returns a gomock.Matcher which returns true for the given context, of any
|
// returns a gomock.Matcher which returns true for the given context, and any
|
||||||
// child contexts of it.
|
// child contexts of it.
|
||||||
//
|
//
|
||||||
// If ctx was not returned from New, the resulting matcher will ALWAYS return
|
// If ctx was not returned from New, the resulting matcher will ALWAYS return
|
||||||
// false.
|
// false.
|
||||||
func Is(ctx context.Context) gomock.Matcher {
|
func Eq(ctx context.Context) gomock.Matcher {
|
||||||
return WithValue(ctxKey, getValue(ctx))
|
return WithValue(ctxKey, getValue(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is accepts a context with a gomockctx ID value (as returned from New), and
|
||||||
|
// returns a gomock.Matcher which returns true for the given context, and any
|
||||||
|
// child contexts of it.
|
||||||
|
//
|
||||||
|
// If ctx was not returned from New, the resulting matcher will ALWAYS return
|
||||||
|
// false.
|
||||||
|
//
|
||||||
|
// Deprecated: Renamed to Eq().
|
||||||
|
func Is(ctx context.Context) gomock.Matcher {
|
||||||
|
return Eq(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// ID returns the gomockctx ID value in the given context, or a empty string if
|
// ID returns the gomockctx ID value in the given context, or a empty string if
|
||||||
// the context does not have a gomockctx ID value.
|
// the context does not have a gomockctx ID value.
|
||||||
func ID(ctx context.Context) string {
|
func ID(ctx context.Context) string {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func TestNew(t *testing.T) {
|
|||||||
assert.Len(t, ids, limit)
|
assert.Len(t, ids, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIs(t *testing.T) {
|
func TestEq(t *testing.T) {
|
||||||
type strKey string
|
type strKey string
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
@@ -100,7 +100,7 @@ func TestIs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := Is(tt.args.ctx)
|
got := Eq(tt.args.ctx)
|
||||||
|
|
||||||
assert.Implements(t, (*gomock.Matcher)(nil), got)
|
assert.Implements(t, (*gomock.Matcher)(nil), got)
|
||||||
|
|
||||||
@@ -109,6 +109,10 @@ func TestIs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIs(t *testing.T) {
|
||||||
|
TestEq(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestID(t *testing.T) {
|
func TestID(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user