Skip to content

romdo/gomockctx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2ca1e1f · Oct 13, 2023

History

21 Commits
Oct 13, 2023
Feb 15, 2022
Oct 13, 2023
Oct 13, 2023
Feb 14, 2022
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Oct 13, 2023
Feb 14, 2022
Oct 13, 2023
Oct 13, 2023

Repository files navigation

gomockctx

Go package with gomock helpers for matching context.Context.

Go Reference GitHub tag (latest SemVer) Actions Status Coverage GitHub issues GitHub pull requests License Status

Import

import "github.com/romdo/gomockctx"

Usage

Match against a specific context or any of its child contexts:

// Create a context with a gomockctx ID value.
ctx := gomockctx.New(context.Background())

// Match against a context with a gomockctx ID.
someMock.EXPECT().
	Get(gomockctx.Eq(ctx), "foo").
	Return("bar", nil)

// Use context with gomockctx ID when calling function.
someMock.Get(ctx, "foo")

Match against a context containing a specific value:

someMock.EXPECT().
	Get(gomockctx.WithValue(myCtxKey, "hello"), "foo").
	Return("bar", nil)

Match against any context:

someMock.EXPECT().
	Get(gomockctx.Any(), "foo").
	Return("bar", nil)

Documentation

Please see the Go Reference.

License

MIT