mockengine

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mockengine provides a loopback-only, schema-generated OpenAPI contract server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation struct {
	ID, Method, Path string
	Groups           []string
	Command          string
	Ignored          bool
	Args             []string
	Query            map[string]string
	// PositionalQuery names the required query parameters, which the CLI
	// takes as positional arguments after the path ones, in this order.
	PositionalQuery []string
	Body            []byte
	Status          int
	Response        []byte
}

func (Operation) QueryFlags

func (o Operation) QueryFlags() []string

QueryFlags are the CLI flags of the optional query parameters, sorted.

type Request

type Request struct {
	Method, Path, OperationID, Authorization string
	Body                                     []byte
	Query                                    string
	Rejected                                 bool
}

Request includes intentional bearer rejections as well as accepted requests.

type Server

type Server struct {
	URL        string
	Document   *openapi3.T
	Operations []Operation

	// Authenticate, when set, checks bearer tokens, such as against the
	// mockauth server that issued them, instead of accepting any.
	Authenticate func(token string) error
	// Unbounded keeps serving once the request record is full, for a
	// long-running mock: it then stops recording.
	Unbounded bool
	// contains filtered or unexported fields
}

func Build

func Build(data []byte) (*Server, error)

Build precomputes immutable fixtures serially; no random generator is shared by handlers. Call Listen before serving requests.

func New

func New(t testing.TB, data []byte) *Server

New serves the mock for the duration of a test.

func (*Server) Errors

func (s *Server) Errors() []error

func (*Server) Listen

func (s *Server) Listen(url string) error

Listen sets the URL the mock is served at; requests are routed under it and under its /api path.

func (*Server) RejectBearer

func (s *Server) RejectBearer(token string)

func (*Server) Requests

func (s *Server) Requests() []Request

func (*Server) RespondWithStatus

func (s *Server) RespondWithStatus(t testing.TB, operationID string, status int) []byte

RespondWithStatus selects a declared response (or its range/default fallback). Bodies are generated from the unchanged contract, never per-operation fixtures.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers an operation with its generated response, after validating the request against the document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL