Documentation ¶
Overview ¶
Package gqlmock provides utilities to mock a GraphQL API for tests.
Index ¶
- func AssertRequest(t *testing.T, expected gomock.Matcher, req *graphql.Request)
- func WithOpName(opName string) gomock.Matcher
- func WithVariables(varMatchers ...*GQLVarMatcher) gomock.Matcher
- type GQLVarMatcher
- type MockClient
- func (c *MockClient) AllRequests() []*graphql.Request
- func (c *MockClient) AllStubsUsed() bool
- func (c *MockClient) MakeRequest(ctx context.Context, req *graphql.Request, resp *graphql.Response) error
- func (c *MockClient) StubAnyOnce(responseJSON string)
- func (c *MockClient) StubMatchOnce(requestMatcher gomock.Matcher, responseJSON string)
- func (c *MockClient) StubOnce(query func(client graphql.Client), responseJSON string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertRequest ¶
AssertMatches asserts that a GQL request matches a gomock Matcher.
func WithOpName ¶
WithOpName matches any GraphQL request with the given OpName.
func WithVariables ¶
func WithVariables(varMatchers ...*GQLVarMatcher) gomock.Matcher
WithVariables matches any GraphQL request with the given variables.
Types ¶
type GQLVarMatcher ¶
GQLVar matches a query variable with the right name and value.
func (*GQLVarMatcher) String ¶
func (m *GQLVarMatcher) String() string
type MockClient ¶
type MockClient struct {
// contains filtered or unexported fields
}
MockClient is a mock implementation of the genqlient Client interface.
Use `StubOnce` to tell it what response to return for a given request. The mock client returns an error by default for unstubbed requests.
Use `AllStubsUsed` to check that all stubbed requests were made.
func NewMockClient ¶
func NewMockClient() *MockClient
func (*MockClient) AllRequests ¶
func (c *MockClient) AllRequests() []*graphql.Request
AllRequests returns all requests made to the mock client.
func (*MockClient) AllStubsUsed ¶
func (c *MockClient) AllStubsUsed() bool
AllStubsUsed reports whether every stubbed response was matched.
func (*MockClient) MakeRequest ¶
func (*MockClient) StubAnyOnce ¶
func (c *MockClient) StubAnyOnce(responseJSON string)
StubAnyOnce registers a response for the next request.
func (*MockClient) StubMatchOnce ¶
func (c *MockClient) StubMatchOnce( requestMatcher gomock.Matcher, responseJSON string, )
StubMatchOnce registers a response for a matching request.
The next time a request matching `requestMatcher` is made, the `responseJSON` is used to fill in the response.
func (*MockClient) StubOnce ¶
func (c *MockClient) StubOnce( query func(client graphql.Client), responseJSON string, )
StubOnce registers a response for a specific request.
The `query` argument is a function that uses the given client to make the expected GraphQL request. The next time such a request is made, the `responseJSON` is used to fill in the response.