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
- type Request
- type Server
- func (s *Server) Answer(call, body string)
- func (s *Server) AnswerMade(call, body string)
- func (s *Server) AnswerText(call, contentType, body string)
- func (s *Server) AnswerTextWhen(call, param, value, contentType, body string)
- func (s *Server) AnswerWhen(call, param, value, body string)
- func (s *Server) Calls() []string
- func (s *Server) Client() *dockhand.Client
- func (s *Server) Fail(call string, status int, message string)
- func (s *Server) FailWhen(call, param, value string, status int, message string)
- func (s *Server) Last(call string) Request
- func (s *Server) Requests(call string) []Request
- func (s *Server) Then(call string, do func(Request))
- func (s *Server) Unauthorized()
Constants ¶
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 ¶
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 ¶
NewOpen starts a canned Dockhand with its login switched off: it expects no token, and fails the test when sent one.
func (*Server) Answer ¶
Answer makes a call - a method and a path, "GET /api/environments" - answer 200 with the JSON given.
func (*Server) AnswerMade ¶
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 ¶
AnswerText makes a call answer 200 with something that is not JSON: a stream of events, a file.
func (*Server) AnswerTextWhen ¶
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 ¶
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) Fail ¶
Fail makes a call answer as Dockhand does when it refuses one: the status, and its reason as {"error": ...}.
func (*Server) Last ¶
Last is the most recent call made of one kind; it fails the test when there was none.
func (*Server) Then ¶
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.