dockhandtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package dockhandtest is a canned Dockhand for tests: it answers the API calls a test tells it to and records what it was asked. Every request it gets is also held against the definitions sdk/dockhand is generated from - the call must be one the API has, and every query parameter sent must be one that call takes - so a test that only meant to check an answer also proves the request was one the real server takes.

The live suites are what prove the canned answers match a real server.

Index

Constants

View Source
const Token = "dh_0000000000000000000000000000000000000000000"

Token is the API token the canned server expects, in the shape Dockhand mints them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Method string
	// Path is the call's path as sent: /api/containers/web/logs
	Path  string
	Query url.Values
	// Accept is what the call said it would take for an answer: JSON alone, or anything for a call asked as a job
	Accept string
	// Body is what was sent with it, as it came
	Body string
}

Request is one call the canned server was sent.

type Server

type Server struct {
	// URL is the address to give a client
	URL string
	// contains filtered or unexported fields
}

Server is a canned Dockhand.

func New

func New(tb testing.TB) *Server

New starts a canned Dockhand with its login on, closed when the test ends. It answers nothing until told to (Answer, Fail): a call with no answer fails the test.

func NewOpen

func NewOpen(tb testing.TB) *Server

NewOpen starts a canned Dockhand with its login switched off: it expects no token, and fails the test when sent one.

func (*Server) Answer

func (s *Server) Answer(call, body string)

Answer makes a call - a method and a path, "GET /api/environments" - answer 200 with the JSON given.

func (*Server) AnswerMade

func (s *Server) AnswerMade(call, body string)

AnswerMade is Answer for a call that answers 201, as the ones that make something and say so by their status do.

func (*Server) AnswerText

func (s *Server) AnswerText(call, contentType, body string)

AnswerText makes a call answer 200 with something that is not JSON: a stream of events, a file.

func (*Server) AnswerTextWhen

func (s *Server) AnswerTextWhen(call, param, value, contentType, body string)

AnswerTextWhen is AnswerText for a call sent a query parameter with a value: the archive of one path inside a container, where another path has another.

func (*Server) AnswerWhen

func (s *Server) AnswerWhen(call, param, value, body string)

AnswerWhen is Answer for a call sent a query parameter with a value: one environment's containers for that environment, where Answer is the same containers whichever is asked for. A call that matches no such answer falls back to the call's own.

func (*Server) Calls

func (s *Server) Calls() []string

Calls is every call made, in order, as "METHOD /path".

func (*Server) Client

func (s *Server) Client() *dockhand.Client

Client is a client for the canned server, made the way its login wants.

func (*Server) Fail

func (s *Server) Fail(call string, status int, message string)

Fail makes a call answer as Dockhand does when it refuses one: the status, and its reason as {"error": ...}.

func (*Server) FailWhen

func (s *Server) FailWhen(call, param, value string, status int, message string)

FailWhen is Fail for a call sent a query parameter with a value.

func (*Server) Last

func (s *Server) Last(call string) Request

Last is the most recent call made of one kind; it fails the test when there was none.

func (*Server) Requests

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

Requests are the calls made of one kind, in order.

func (*Server) Then

func (s *Server) Then(call string, do func(Request))

Then has the canned server do something when a call is made, before it answers: change what another call answers from then on, which is how a write comes to be read back. A nil do is nothing more to be done.

func (*Server) Unauthorized

func (s *Server) Unauthorized()

Unauthorized makes every call answer as a Dockhand with its login on does to a token it does not take, whatever was set for it.

Jump to

Keyboard shortcuts

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