Documentation
¶
Overview ¶
Package mocks hosts the M9 shared mock RoundTrippers + PluginContext builder consumed by `*_test.go` files across the project.
Index ¶
- func NewPluginContext(t *testing.T, opts ...PluginContextOption) *plugins.PluginContext
- type GraphQLMux
- func (m *GraphQLMux) Calls(opName string) int
- func (m *GraphQLMux) OnBody(opName string, status int, body string)
- func (m *GraphQLMux) OnFile(opName, fixturePath string)
- func (m *GraphQLMux) OnFunc(opName string, fn func(vars map[string]any) (status int, body string))
- func (m *GraphQLMux) RoundTrip(req *http.Request) (*http.Response, error)
- type PluginContextOption
- func WithData(d *plugins.Data) PluginContextOption
- func WithGraphQL(mux *GraphQLMux) PluginContextOption
- func WithInputs(in map[string]any) PluginContextOption
- func WithLogger(l *slog.Logger) PluginContextOption
- func WithREST(mux *RESTMux) PluginContextOption
- func WithSettings(s *config.Settings) PluginContextOption
- func WithToken(tok config.Token) PluginContextOption
- type RESTMux
- func (m *RESTMux) Calls(path string) int
- func (m *RESTMux) OnBody(path string, status int, body string)
- func (m *RESTMux) OnFile(path, fixturePath string)
- func (m *RESTMux) OnFunc(path string, ...)
- func (m *RESTMux) OnHeader(path string, status int, body string, header http.Header)
- func (m *RESTMux) RoundTrip(req *http.Request) (*http.Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPluginContext ¶
func NewPluginContext(t *testing.T, opts ...PluginContextOption) *plugins.PluginContext
NewPluginContext bundles a *GraphQLMux + *RESTMux into a *plugins.PluginContext ready for `Plugin.Run`. Defaults:
- Settings: &config.Settings{Repositories: 100}
- Inputs: map[string]any{"user": "octocat"}
- Data: plugins.NewData()
- Logger: slog.New(slog.NewTextHandler(io.Discard, nil))
- Token: config.NewToken("MOCKED_TOKEN")
Either WithGraphQL or WithREST (or both) MUST be supplied; without them the returned PluginContext has nil clients and most plugins will Skipped-out at their early-return guard.
Types ¶
type GraphQLMux ¶
type GraphQLMux struct {
// contains filtered or unexported fields
}
GraphQLMux dispatches genqlient GraphQL requests by the JSON request body's `operationName`. Implements http.RoundTripper — callers wire it into `internal/githubapi.NewGraphQL` via `httpx.Options.Transport` + `DisableRetries: true`.
Goroutine-safe: dispatch (RoundTrip) takes an RLock; registration (On*) takes a write lock.
Unknown operationName triggers t.Fatalf so missing handlers surface immediately with an actionable list of registered ops.
func NewGraphQLMux ¶
func NewGraphQLMux(t *testing.T) *GraphQLMux
NewGraphQLMux constructs an empty mux. The returned value is goroutine-safe and registers a t.Cleanup that resets handler state at end of test.
func (*GraphQLMux) Calls ¶
func (m *GraphQLMux) Calls(opName string) int
Calls returns the number of times RoundTrip dispatched to the given operationName.
func (*GraphQLMux) OnBody ¶
func (m *GraphQLMux) OnBody(opName string, status int, body string)
OnBody registers an inline-body handler.
func (*GraphQLMux) OnFile ¶
func (m *GraphQLMux) OnFile(opName, fixturePath string)
OnFile registers a 200 OK fixture-file-backed handler keyed by operationName. `fixturePath` is relative to `tests/fixtures/`.
func (*GraphQLMux) OnFunc ¶
OnFunc registers a per-call dynamic handler. The decoded `variables` map is passed in so cursor-aware paging mocks can branch on it.
type PluginContextOption ¶
type PluginContextOption func(*pluginContextConfig)
PluginContextOption is the functional-options surface for NewPluginContext.
func WithData ¶
func WithData(d *plugins.Data) PluginContextOption
WithData overrides the default empty Data envelope.
func WithGraphQL ¶
func WithGraphQL(mux *GraphQLMux) PluginContextOption
WithGraphQL installs the given mux as the PluginContext's GraphQL client.
func WithInputs ¶
func WithInputs(in map[string]any) PluginContextOption
WithInputs overrides the default inputs map.
func WithLogger ¶
func WithLogger(l *slog.Logger) PluginContextOption
WithLogger overrides the default no-op logger.
func WithREST ¶
func WithREST(mux *RESTMux) PluginContextOption
WithREST installs the given mux as the PluginContext's REST client.
func WithSettings ¶
func WithSettings(s *config.Settings) PluginContextOption
WithSettings overrides the default Settings (Repositories: 100).
func WithToken ¶
func WithToken(tok config.Token) PluginContextOption
WithToken overrides the default MOCKED_TOKEN sentinel.
type RESTMux ¶
type RESTMux struct {
// contains filtered or unexported fields
}
RESTMux is a per-path RoundTripper for REST tests. Construct with NewRESTMux(t); register handlers via OnFile / OnBody / OnHeader / OnFunc; consume the *http.Response via your code-under-test through the project's `internal/githubapi.NewREST` (pass it as `httpx.Options.Transport` together with `DisableRetries: true`).
Goroutine-safe: dispatch (RoundTrip) takes an RLock; registration (On*) takes a write lock. Multiple `t.Run` + `t.Parallel` subtests sharing one mux do not race.
func NewRESTMux ¶
NewRESTMux constructs a RESTMux ready to register handlers on. Registers a t.Cleanup that resets handler state at end of test.
func (*RESTMux) OnFile ¶
OnFile registers a 200 OK fixture-file-backed handler for the given request path. `fixturePath` is relative to `tests/fixtures/`. The file MUST exist at first matching dispatch; missing files trigger t.Fatalf.
func (*RESTMux) OnFunc ¶
func (m *RESTMux) OnFunc(path string, fn func(req *http.Request) (status int, body string, header http.Header))
OnFunc registers a per-call dynamic handler that sees the full *http.Request (use req.URL.RawQuery to inspect query strings).