mock

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call added in v0.1.4

type Call struct {
	Op   string
	Args model.Encodable
}

Call records an invocation of a Caller operation.

type Caller added in v0.1.4

type Caller struct {
	Calls []Call

	// CannedResult is passed to the Call callback.
	CannedResult []byte
	// CannedError is passed to the Call callback.
	CannedError error
}

Caller fakes the call-side contract, recording operations and allowing canned responses to be configured.

func (*Caller) Call added in v0.1.4

func (c *Caller) Call(op string, args model.Encodable, callback func(result []byte, err error))

func (*Caller) Dispatch added in v0.1.4

func (c *Caller) Dispatch(op string, args model.Encodable)

type Context

type Context struct {
	InMethod string
	InPath   string
	InBody   []byte

	Status int
	// contains filtered or unexported fields
}

Context buffers the response and lets tests set the request fields. Unlike the base router.Context contract (single-goroutine ownership), this mock IS safe for concurrent use: its role is to let the test goroutine observe (ResponseBody) while a handler goroutine writes.

func (*Context) Body

func (c *Context) Body() []byte

func (*Context) Cookie

func (c *Context) Cookie(name string) (router.Cookie, bool)

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) Method

func (c *Context) Method() string

func (*Context) Path

func (c *Context) Path() string

func (*Context) ResponseBody

func (c *Context) ResponseBody() []byte

ResponseBody devuelve una copia del cuerpo de respuesta bufferizado.

func (*Context) SetCookie

func (c *Context) SetCookie(cookie router.Cookie)

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

func (*Context) SetUserID added in v0.1.2

func (c *Context) SetUserID(id string)

func (*Context) SetValue

func (c *Context) SetValue(key string, v any)

func (*Context) UserID added in v0.1.2

func (c *Context) UserID() string

func (*Context) Value

func (c *Context) Value(key string) any

func (*Context) Write

func (c *Context) Write(b []byte) (int, error)

func (*Context) WriteStatus

func (c *Context) WriteStatus(code int)

type Route

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

Route implementa router.Route para el mock, grabando las anotaciones de permiso.

func (*Route) Public added in v0.1.2

func (r *Route) Public() router.Route

func (*Route) Requires

func (r *Route) Requires(resource model.Resource, action model.Action) router.Route

type Router

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

Router graba las rutas registradas y permite dispararlas en un test.

Guarda *Route, no RouteInfo: las anotaciones de permiso (Public/Requires) se encadenan DESPUÉS de registrar la ruta, así que una copia por valor tomada en el registro nunca las vería y el mock afirmaría que toda ruta es privada.

func (*Router) Delete

func (r *Router) Delete(path string, h router.HandlerFunc) router.Route

func (*Router) Get

func (r *Router) Get(path string, h router.HandlerFunc) router.Route

func (*Router) Handle

func (r *Router) Handle(method, path string, h router.HandlerFunc) router.Route

func (*Router) Invoke

func (r *Router) Invoke(method, path string, ctx router.Context)

Invoke ejecuta el handler registrado para un método y ruta.

func (*Router) Options

func (r *Router) Options(path string, h router.HandlerFunc) router.Route

func (*Router) Post

func (r *Router) Post(path string, h router.HandlerFunc) router.Route

func (*Router) PublicAsset added in v0.1.7

func (r *Router) PublicAsset(path string, h router.HandlerFunc)

PublicAsset registra un archivo servido al navegador: público por construcción, sin Route que devolver — no hay permiso que colgarle.

func (*Router) PublicDir added in v0.1.7

func (r *Router) PublicDir(prefix string, dir string)

PublicDir registra un directorio servido bajo un prefijo.

func (*Router) Put

func (r *Router) Put(path string, h router.HandlerFunc) router.Route

func (*Router) Routes

func (r *Router) Routes() []router.RouteInfo

Routes proyecta las rutas registradas en el momento de la consulta, ya con sus anotaciones de permiso aplicadas.

func (*Router) Socket

func (r *Router) Socket(path string, h router.SocketFunc) router.Route

func (*Router) Stream

func (r *Router) Stream(path string, h router.StreamFunc) router.Route

func (*Router) Use

func (r *Router) Use(m ...router.Middleware)

Jump to

Keyboard shortcuts

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