Documentation
¶
Index ¶
- type Call
- type Caller
- type Config
- type Context
- func (c *Context) Body() []byte
- func (c *Context) Cookie(name string) (router.Cookie, bool)
- func (c *Context) GetHeader(key string) string
- func (c *Context) Method() string
- func (c *Context) Path() string
- func (c *Context) ResponseBody() []byte
- func (c *Context) SetCookie(cookie router.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetUserID(id string)
- func (c *Context) SetValue(key string, v any)
- func (c *Context) UserID() string
- func (c *Context) Value(key string) any
- func (c *Context) Write(b []byte) (int, error)
- func (c *Context) WriteStatus(code int)
- type Route
- type Router
- func (r *Router) Configure(cfg Config)
- func (r *Router) Delete(path string, h router.HandlerFunc) router.Route
- func (r *Router) Get(path string, h router.HandlerFunc) router.Route
- func (r *Router) Handle(method, path string, h router.HandlerFunc) router.Route
- func (r *Router) Invoke(method, path string, ctx router.Context)
- func (r *Router) Options(path string, h router.HandlerFunc) router.Route
- func (r *Router) Post(path string, h router.HandlerFunc) router.Route
- func (r *Router) PublicAsset(path string, h router.HandlerFunc)
- func (r *Router) PublicDir(prefix string, dir string)
- func (r *Router) Put(path string, h router.HandlerFunc) router.Route
- func (r *Router) Routes() []router.RouteInfo
- func (r *Router) Socket(path string, h router.SocketFunc) router.Route
- func (r *Router) Stream(path string, h router.StreamFunc) router.Route
- func (r *Router) Use(m ...router.Middleware)
- func (r *Router) Verify() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.
type Config ¶ added in v0.1.10
type Config struct {
// Authn establishes identity. It runs BEFORE the access gate: a gate that runs first
// can never be satisfied, and every guarded route becomes a permanent 403.
Authn router.Middleware
// Authorize answers whether an identity holds a permission. nil DENIES.
Authorize model.Authorizer
}
Config declares WHO the caller is and WHAT they may do — the same two seams the real implementations expose (server/httpd, goflare/edge). The zero value is legal and means "no authentication, no authorizer": public routes work, and every guarded route denies.
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) ResponseBody ¶
ResponseBody devuelve una copia del cuerpo de respuesta bufferizado.
func (*Context) WriteStatus ¶
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route implementa router.Route para el mock, grabando las anotaciones de permiso.
func (*Route) Authenticated ¶ added in v0.1.9
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is an in-memory implementation of router.Router for tests.
It is NOT a recorder. It enforces the same contract the deployed implementations do — method routing, closed-by-default access, identity before the gate, middleware behind it — and it proves that by passing router/conformance, exactly like they must.
It used to be a recorder: Invoke called the handler directly and Use was discarded. That made it a fake that could not fail, so every consumer testing against it was testing a fantasy — a guarded route "worked" in their tests and answered 403 in production. That is not a hypothetical: it is how goflare shipped an unusable file API with a green suite.
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) Configure ¶ added in v0.1.10
Configure installs the identity and authorization seams. Call it before dispatching.
func (*Router) Invoke ¶
Invoke drives one request through the FULL pipeline: identity, access gate, middleware, handler — the same order a deployed implementation uses.
It used to call the handler directly, skipping the gate. That is why it is worth saying out loud: a fake that cannot reject is not testing your access control, it is hiding it.
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
PublicDir registra un directorio servido bajo un prefijo.
func (*Router) Routes ¶
Routes proyecta las rutas registradas en el momento de la consulta, ya con sus anotaciones de permiso aplicadas.
func (*Router) Use ¶
func (r *Router) Use(m ...router.Middleware)
Use registers middleware. It runs BEHIND the access gate: a rejected request must not execute business logic.