technitiumtest

package
v0.2.0 Latest Latest
Warning

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

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

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

View Source
const Token = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"

Token is the API token the canned server expects.

Variables

This section is empty.

Functions

func Sent

func Sent(path, param string) bool

Sent reports whether any canned server of this test binary has been sent a parameter with a call, so far.

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

func New(tb testing.TB) *Server

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

func (s *Server) Accept(token string)

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) Answer

func (s *Server) Answer(path, response string)

Answer makes a call answer ok with the JSON given under "response".

func (*Server) AnswerText

func (s *Server) AnswerText(path, text string)

AnswerText makes a call answer with a text file, as the calls that export a list do: one entry a line.

func (*Server) AnswerWhen

func (s *Server) AnswerWhen(path, param, value, response string)

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

func (s *Server) AnswerWhole(path, body string)

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

func (s *Server) Fail(path, status, message string)

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) FailWhen

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

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

func (*Server) Last

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

Last is the most recent call made to a path; it fails the test when there was none.

func (*Server) Requests

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

Requests are the calls made to a path, in order.

func (*Server) Then

func (s *Server) Then(path 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.

Jump to

Keyboard shortcuts

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