Documentation
¶
Overview ¶
Package servertest has the parts of a server for tests and examples: a clock you set, an authenticator that trusts a header, and a notifier, flows, agents, books, files and an audit log that remember what they were given; and, for the tests of a project's pages, a browser with no script (Browser) and the form of a page as a browser holds it (Form). None of them is for production.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrFailed = errors.New("failed, as the test said")
ErrFailed is the failure of the parts that are told to fail.
Functions ¶
This section is empty.
Types ¶
type Agents ¶
Agents remembers what was asked. Answer, when set, is called for each new ask after it is remembered (in its own goroutine), to answer it as an agent would.
type AuditLog ¶
type AuditLog struct {
// contains filtered or unexported fields
}
AuditLog remembers its entries.
func (*AuditLog) Entries ¶
func (a *AuditLog) Entries() []server.AuditEntry
Entries answers the entries.
type Books ¶
type Books struct {
Refuse func(server.BookCall) string
Fail func(server.BookCall) error
// contains filtered or unexported fields
}
Books are books in memory that answer done to every call, and done_before to a call they made before: the same call (hold, post or release) of the same effect with the same arguments, as a book that keys its holds by the ticket and the try answers a call given again. Refuse, when set, refuses a call with its reason; Fail, when set, answers a call with an error, as books that do not answer do, and the call is not made. With a memstore, a call counts only once its move is saved.
type Browser ¶
type Browser struct {
Handler http.Handler
// Base is the scheme and the host requests go to; http://localhost:8080 when "" (a loopback
// host, which the development sign-in answers).
Base string
// Header is sent with each request.
Header http.Header
// contains filtered or unexported fields
}
Browser is a browser with no script on the pages of a handler, for tests: it sends what a browser sends from the server's own pages (Sec-Fetch-Site same-origin, Sec-Fetch-Mode navigate, Accept text/html) to Base, with Header and the cookies the answers set (a cookie set with a negative MaxAge is forgotten), and follows no redirect.
func (*Browser) Get ¶
func (b *Browser) Get(target string) *httptest.ResponseRecorder
Get sends GET target (a path of the server, with its query).
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock is a clock that tells the time it is set to.
type Files ¶
Files keeps files in memory: it is memstore.Files, which a server that keeps its tickets in memory keeps its attachments in. With a Base, URL answers Base/<id>; without one, "".
type Flows ¶
type Flows struct {
// contains filtered or unexported fields
}
Flows remembers the flows launched.
type Form ¶
type Form struct {
// Action is where it posts.
Action string
// Values are the values it posts, but the files and the button.
Values url.Values
// contains filtered or unexported fields
}
Form is the form of a page as a browser holds it: what it posts, as the person leaves it.
func ReadForm ¶
ReadForm reads the form of a page (the one of class form; the bar's is another) as a browser does when the page is shown: its controls in their order, but those in a <template>. A page with no such form is an error. The page is read as the framework writes its pages, well-formed XML with the named characters of HTML; a page that is not is an error too.
func (*Form) Attach ¶
Attach chooses a file for a file control: its name and what it holds. The post gives it the type a browser gives a file of that name (application/pdf for a name that ends in .pdf, …; application/octet-stream for an ending it does not know).
func (*Form) Body ¶
Body is what a browser posts with a button: the body and its Content-Type (the button is sent as the page's buttons send it, _do=<value>). A button the form does not have is an error.
type Header ¶
type Header struct{}
Header is an authenticator that trusts a header to say who sends the request: X-Person (the person's ID) and X-Roles (their roles, apart with commas; "staff" when it is not there). For tests and examples only: anyone who can send a request can say they are anyone.