mock

package
v0.38.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AryaStark *entity.User

AryaStark is a mocked user (visitor)

View Source
var AvengersTenant *entity.Tenant

AvengersTenant is a mocked tenant

View Source
var DemoTenant *entity.Tenant

DemoTenant is a mocked tenant

View Source
var JonSnow *entity.User

JonSnow is a mocked user (administrator)

Functions

func GIFHeader added in v0.38.0

func GIFHeader(width, height int) []byte

GIFHeader returns the header of a GIF with the given logical screen dimensions (max 65535). It contains no image data: enough for image.DecodeConfig, but not for image.Decode.

func NewNoopTask added in v0.11.0

func NewNoopTask() worker.Task

NewNoopTask returns a worker task that does nothing

func UniformGrayPNG added in v0.38.0

func UniformGrayPNG(width, height, bitDepth int, transparent bool) []byte

UniformGrayPNG is like UniformPNG, with the given bit depth (1, 2, 4, 8 or 16), and a tRNS chunk (making one gray level transparent) when transparent is true.

func UniformPNG added in v0.38.0

func UniformPNG(width, height int) []byte

UniformPNG returns a valid 1-bit grayscale PNG of the given dimensions where every pixel is black. It is streamed row by row, so generating it never allocates the full image in memory. Large dimensions compress extremely well, which makes this useful for building "decompression bomb" images in tests (e.g. 12000x12000 is only a few KB). Results are cached, callers must not modify the returned slice.

Types

type Server

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

Server is a HTTP server wrapper for testing purpose

func NewServer

func NewServer() *Server

NewServer creates a new server for HTTP testing

func NewSingleTenantServer

func NewSingleTenantServer() *Server

NewSingleTenantServer creates a new multitenant test server

func (*Server) AddCookie added in v0.5.0

func (s *Server) AddCookie(name string, value string) *Server

AddCookie add key-value to current context cookies

func (*Server) AddHeader added in v0.5.0

func (s *Server) AddHeader(name string, value string) *Server

AddHeader add key-value to current context headers

func (*Server) AddParam added in v0.7.0

func (s *Server) AddParam(name string, value any) *Server

AddParam to current context route parameters

func (*Server) AsUser added in v0.5.0

func (s *Server) AsUser(user *entity.User) *Server

AsUser set current context user

func (*Server) Engine added in v0.11.0

func (s *Server) Engine() *web.Engine

Engine returns current engine from mocked server

func (*Server) Execute

func (s *Server) Execute(handler web.HandlerFunc) (int, *httptest.ResponseRecorder)

Execute given handler and return response

func (*Server) ExecuteAsJSON

func (s *Server) ExecuteAsJSON(handler web.HandlerFunc) (int, *jsonq.Query)

ExecuteAsJSON given handler and return json response

func (*Server) ExecuteAsPage added in v0.20.0

func (s *Server) ExecuteAsPage(handler web.HandlerFunc) (int, *web.Props)

ExecuteAsPage given handler and return page props

func (*Server) ExecutePost

func (s *Server) ExecutePost(handler web.HandlerFunc, body string) (int, *httptest.ResponseRecorder)

ExecutePost executes given handler as POST and return response

func (*Server) ExecutePostAsJSON added in v0.6.0

func (s *Server) ExecutePostAsJSON(handler web.HandlerFunc, body string) (int, *jsonq.Query)

ExecutePostAsJSON executes given handler as POST and return json response

func (*Server) OnTenant added in v0.5.0

func (s *Server) OnTenant(tenant *entity.Tenant) *Server

OnTenant set current context tenant

func (*Server) Use

func (s *Server) Use(middleware web.MiddlewareFunc) *Server

Use adds a new middleware to pipeline

func (*Server) WithURL added in v0.5.0

func (s *Server) WithURL(fullURL string) *Server

WithURL set current context Request URL

type Worker added in v0.10.0

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

Worker is fake wrapper for background worker

func NewWorker added in v0.10.0

func NewWorker() *Worker

NewWorker creates a new worker for worker testing

func (*Worker) AsUser added in v0.10.0

func (w *Worker) AsUser(user *entity.User) *Worker

AsUser set current context user

func (*Worker) Execute added in v0.10.0

func (w *Worker) Execute(task worker.Task) error

Execute given task with current context

func (*Worker) OnTenant added in v0.10.0

func (w *Worker) OnTenant(tenant *entity.Tenant) *Worker

OnTenant set current context tenant

func (*Worker) WithBaseURL added in v0.14.0

func (w *Worker) WithBaseURL(baseURL string) *Worker

WithBaseURL set current context baseURL

Jump to

Keyboard shortcuts

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