Documentation
¶
Overview ¶
Package technitiumtest is a canned Technitium server 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 vendored API document (sdk/apidoc) - the call must be one the document has, at its current path, and every parameter sent must be one the document gives that call - 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
- func Sent(path, param string) bool
- type Request
- type Server
- func (s *Server) Accept(token string)
- func (s *Server) Answer(path, response string)
- func (s *Server) AnswerText(path, text string)
- func (s *Server) AnswerWhen(path, param, value, response string)
- func (s *Server) AnswerWhole(path, body string)
- func (s *Server) Fail(path, status, message string)
- func (s *Server) FailWhen(path, param, value, status, message string)
- func (s *Server) Last(path string) Request
- func (s *Server) Requests(path string) []Request
- func (s *Server) Then(path string, do func(Request))
Constants ¶
const Token = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
Token is the API token the canned server expects.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Request ¶
type Request struct {
Method string
// Path is the call's path under /api/: zones/list
Path string
Params url.Values
// File is the file the call was sent, nil for a call sent none, and
// FileName the name it was sent under
File []byte
FileName string
// Token is the bearer token the call carried, "" for none
Token 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 Technitium server.
func New ¶
New starts a canned server that is closed when the test ends. It answers nothing until told to (Answer, Fail): a call with no answer fails the test.
func (*Server) Accept ¶
Accept has the canned server take another token beside its own: the one a test's sign-in or new token answers with, which the calls after it carry.
func (*Server) AnswerText ¶
AnswerText makes a call answer with a text file, as the calls that export a list do: one entry a line.
func (*Server) AnswerWhen ¶
AnswerWhen makes a call answer ok with the JSON given under "response" when it is sent a parameter with a value: one zone's records for that zone, where Answer is the same records whatever is asked for. A call that matches no such answer falls back to the path's own.
func (*Server) AnswerWhole ¶
AnswerWhole makes a call answer with exactly the body given, for the calls that put their answer beside "status" and for answers that are not the API's at all.
func (*Server) Fail ¶
Fail makes a call answer as the server does when it refuses one: HTTP 200, with the status and the message in the body.
func (*Server) Last ¶
Last is the most recent call made to a path; it fails the test when there was none.