clihelper

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFreePort

func FindFreePort(t *testing.T) int

FindFreePort finds and returns a free TCP port. Deprecated: Use Cmd(t).SetPort(0).Run() instead.

func RunCmd

func RunCmd(t *testing.T, args []string, env []string) (string, func())

RunCmd executes a CLI command with optional environment variables. Returns the combined output (stdout+stderr) and a cleanup function to kill the process.

func StartServer

func StartServer(t *testing.T, port int, schemaFile string, extraArgs ...string) (*exec.Cmd, <-chan error, int)

StartServer starts the oasmock CLI server as a subprocess. Returns the command, an error channel that will receive the exit error, and the actual port used. Deprecated: Use Cmd(t).SetSchema(schemaFile, "").SetPort(port).AddArg(extraArgs...).Run() instead.

func StopServer

func StopServer(t *testing.T, cmd *exec.Cmd)

StopServer stops the CLI server process.

func WaitForServer

func WaitForServer(t *testing.T, port int, timeout time.Duration) bool

WaitForServer waits for the server to be ready by attempting to connect.

Types

type ServerBuilder

type ServerBuilder struct {
	// contains filtered or unexported fields
}

ServerBuilder provides a fluent interface for configuring and starting an oasmock server. No validation is performed - invalid configurations will be caught by the CLI.

func Cmd

func Cmd(t *testing.T) *ServerBuilder

Cmd creates a new ServerBuilder for configuring an oasmock server.

func (*ServerBuilder) AddArg

func (b *ServerBuilder) AddArg(arg string) *ServerBuilder

AddArg adds a raw CLI argument for advanced configuration.

func (*ServerBuilder) DisableCORS

func (b *ServerBuilder) DisableCORS(disable bool) *ServerBuilder

DisableCORS enables or disables CORS headers.

func (*ServerBuilder) DisableControlAPI

func (b *ServerBuilder) DisableControlAPI(disable bool) *ServerBuilder

DisableControlAPI enables or disables the management control API.

func (*ServerBuilder) Run

func (b *ServerBuilder) Run() (*exec.Cmd, <-chan error, int)

Run starts the configured oasmock server and returns the command, error channel, and actual port used (useful when port=0).

func (*ServerBuilder) SetDelay

func (b *ServerBuilder) SetDelay(milliseconds int) *ServerBuilder

SetDelay sets the delay between request and response in milliseconds.

func (*ServerBuilder) SetEnv

func (b *ServerBuilder) SetEnv(env []string) *ServerBuilder

SetEnv sets environment variables for the server process.

func (*ServerBuilder) SetHistorySize

func (b *ServerBuilder) SetHistorySize(size int) *ServerBuilder

SetHistorySize sets the maximum number of requests to keep in history.

func (*ServerBuilder) SetPort

func (b *ServerBuilder) SetPort(port int) *ServerBuilder

SetPort sets the port to listen on. Use 0 to auto-find a free port.

func (*ServerBuilder) SetSchema

func (b *ServerBuilder) SetSchema(schema string, prefix string) *ServerBuilder

SetSchema adds a schema file with an optional prefix. Can be called multiple times to add multiple schemas.

func (*ServerBuilder) SetVerbose

func (b *ServerBuilder) SetVerbose(verbose bool) *ServerBuilder

SetVerbose enables or disables verbose logging.

Jump to

Keyboard shortcuts

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