mock

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mock provides core lifecycle management for devx OpenAPI mock servers. Mock servers are powered by Stoplight Prism (stoplight/prism:5) and run as long-lived background containers, similar to devx-managed databases.

Each mock is identified by a user-defined name (e.g. "stripe") and responds to HTTP requests according to the remote OpenAPI spec it is initialized with.

Environment variable injected by `devx mock list`:

MOCK_<NAME>_URL=http://localhost:<port>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvKey

func EnvKey(name string) string

EnvKey returns the environment variable key for the mock URL injection.

func Remove

func Remove(runtime, name string) error

Remove stops and removes a named mock container.

func Restart

func Restart(runtime, name string) error

Restart stops and restarts a named mock container without removing it.

func WaitForReady

func WaitForReady(port int, timeout time.Duration) error

WaitForReady polls until Prism is actually serving HTTP responses (not just accepting TCP).

Types

type MockInfo

type MockInfo struct {
	Name          string `json:"name"`
	ContainerName string `json:"container"`
	SpecURL       string `json:"spec_url"`
	Port          int    `json:"port"`
	EnvVar        string `json:"env_var"`
	Status        string `json:"status"`
}

MockInfo describes a running devx mock container for the list command.

func List

func List(runtime string) ([]MockInfo, error)

List returns all running devx-managed mock containers.

type MockServer

type MockServer struct {
	Name          string
	SpecURL       string
	ContainerName string
	HostPort      int
}

MockServer holds metadata about a running (or desired) mock server.

func Up

func Up(runtime, name, specURL string, port int) (*MockServer, error)

Up starts a Prism mock container for the given name and remote spec URL. If port is 0 a free port is acquired automatically.

Jump to

Keyboard shortcuts

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