servertest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package servertest runs the HTTP cases each behavior's generated gen/api_<method>_public_test.go lists. Each case is one request to the real handler and middleware with the job client mocked, the way the hand-written domains' handler tests run; the response is checked for its status, its body when the case gives one, and against the generated spec.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnreachable = errors.New("agent unreachable")

ErrUnreachable is the job client failing to reach any agent.

Functions

func Completed

func Completed(
	host string,
	data string,
) *job.Response

Completed is host's answer carrying data, a method's output as JSON. A write's changed is read from it.

func Failed

func Failed(
	host string,
	msg string,
) *job.Response

Failed is host's answer when the method fails there with msg.

func NotFound

func NotFound(
	host string,
) error

NotFound is the error a host answers when it does not have the key.

func Skipped

func Skipped(
	host string,
) *job.Response

Skipped is host's answer when the behavior does not run on its platform.

func TimedOut

func TimedOut(
	host string,
) *job.Response

TimedOut is host's answer when it never replied.

Types

type Case

type Case struct {
	Name    string
	Request Request
	Token   Token
	// Job is what the job client expects; nil expects no job, because the
	// request must be refused before one is queued.
	Job      *Job
	WantCode int
	// WantBody, when set, is the JSON body, with the results in hostname
	// order.
	WantBody string
}

Case is one request and what the job client is asked and answers.

type Harness

type Harness struct {
	// contains filtered or unexported fields
}

Harness serves one behavior's generated routes.

func New

func New(
	t *testing.T,
	spec string,
	routes func(s *server.Server) []server.Route,
) *Harness

New returns a harness for routes, with server1 and server2 as the agents a target can name, and spec, the behavior's generated spec from the repository root, loaded to check responses against.

func (*Harness) Run

func (h *Harness) Run(
	t *testing.T,
	cases []Case,
)

Run sends each case to a fresh server and checks its response.

type Job

type Job struct {
	// contains filtered or unexported fields
}

Job is one call the job client expects and its answer.

func Modify

func Modify(
	target string,
	op string,
	input any,
	replies ...*job.Response,
) *Job

Modify expects a write of op on target with input, answered by replies.

func Query

func Query(
	target string,
	op string,
	input any,
	replies ...*job.Response,
) *Job

Query expects a read of op on target with input, answered by replies: one for a single host, one per host for a broadcast.

func (*Job) Fails

func (j *Job) Fails(
	err error,
) *Job

Fails makes the job client answer err in place of replies.

type Request

type Request struct {
	Method string
	Path   string
	Body   string
}

Request is the HTTP request a case sends.

type Token

type Token int

Token is the token a case sends.

const (
	// Read is a token with the built-in read role.
	Read Token = iota
	// Write is a token with the roles that change a host without admin: automation and operator.
	Write
	// NoToken sends no Authorization header.
	NoToken
	// Lacking is a token whose permissions grant nothing a behavior needs.
	Lacking
	// Admin is a token with the built-in admin role.
	Admin
)

Jump to

Keyboard shortcuts

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