Documentation
¶
Overview ¶
Package testenv runs the whole edge for integration tests: a fake core on a Unix socket, a SQLite store in a temp dir, the background loops and the HTTP API on an httptest server.
Index ¶
- Constants
- Variables
- func CheckContract(t testing.TB, req *http.Request, status int, header http.Header, body []byte)
- func CheckWebhook(t testing.TB, ev map[string]any)
- type Env
- func (e *Env) Do(method, path string, body any) Response
- func (e *Env) DoKey(key, method, path string, body any) Response
- func (e *Env) Eventually(what string, timeout time.Duration, cond func() bool)
- func (e *Env) NewFileServer(body []byte, contentType string) string
- func (e *Env) NewHook(status func(n int, r *http.Request) int) *Hook
- func (e *Env) Restart()
- func (e *Env) Status(session string) string
- func (e *Env) WorkingSession(name, jid string, config any) string
- type Hook
- type HookRequest
- type Options
- type Response
Constants ¶
const AdminKey = "test-admin-key-0123456789"
AdminKey is the admin key every test environment uses.
Variables ¶
var Divergences = map[string]string{
"GET /api/{session}/groups 200": "GOWS answers the list as an array (PaginatorInMemory over the engine's list); the document says object",
}
Divergences are places where WAHA itself does not follow its OpenAPI document, and this edge follows WAHA. Key: "METHOD /path STATUS"; value: why. A response matching one of these is not checked against the schema.
Functions ¶
func CheckContract ¶
CheckContract validates one response against the operation's schema for its status. A status the operation does not document, or a body that is not JSON, is not checked: WAHA documents only its success answers.
Types ¶
type Env ¶
type Env struct {
T testing.TB
URL string
Core *fakecore.Core
App *app.App
HTTP *httptest.Server
// contains filtered or unexported fields
}
Env is one running edge.
func (*Env) Do ¶
Do sends a request with the admin key. body may be nil, a string, []byte or any value to marshal.
func (*Env) Eventually ¶
Eventually polls cond until it holds or the timeout passes.
func (*Env) NewFileServer ¶
NewFileServer serves body with the given content type at every path and returns its URL, for routes that fetch a file by URL.
func (*Env) NewHook ¶
NewHook starts a receiver. status, if set, picks the answer to the n-th request (0-based); default 200.
func (*Env) Restart ¶
func (e *Env) Restart()
Restart stops this edge process and starts a new one, as another worker, on the same store and the same core: a deploy, or a lease handover.
type Hook ¶
type Hook struct {
URL string
// contains filtered or unexported fields
}
Hook is a webhook receiver that records every request.
func (*Hook) Requests ¶
func (h *Hook) Requests() []HookRequest
Requests is every request received so far.
type HookRequest ¶
HookRequest is one received webhook.
func (HookRequest) Event ¶
func (h HookRequest) Event() map[string]any
Event decodes the request as a WAHA envelope.