platformtest

package
v6.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package platformtest runs commands against a fake platform: an httptest server whose endpoints a test declares, which records every request it receives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Home

func Home(t *testing.T) string

Home gives the test an empty home directory. Go reads USERPROFILE for it on Windows and HOME elsewhere, so both are set.

func Stderr added in v6.1.0

func Stderr(t *testing.T, fn func() error) (string, error)

Stderr captures what fn prints to standard error.

func Stdout

func Stdout(t *testing.T, fn func() error) (string, error)

Stdout captures what fn prints.

Types

type Platform

type Platform struct {
	Client *platform.Client
	URL    string
	// contains filtered or unexported fields
}

func New

func New(t *testing.T) *Platform

New starts a fake platform and points the CLI configuration at it.

func (*Platform) Handle

func (p *Platform) Handle(route string, reply func(Request) Reply)

Handle answers "METHOD /path"; a path segment written as * matches any value.

func (*Platform) Reply

func (p *Platform) Reply(route string, reply Reply)

Reply answers a route with a fixed reply.

func (*Platform) Requests

func (p *Platform) Requests(route string) []Request

type Reply

type Reply struct {
	Status  int
	JSON    any
	Body    string
	Headers map[string]string
}

type Request

type Request struct {
	Method string
	Path   string
	Query  map[string][]string
	Header http.Header
	Body   []byte
}

func (Request) JSON

func (r Request) JSON(t *testing.T) any

JSON decodes the request body.

Jump to

Keyboard shortcuts

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