mock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusEP       = "/v1/status"
	RegisterEP     = "/v1/register"
	LoginEP        = "/v1/login"
	AuthenticateEP = "/v1/authenticate"
	RefreshEP      = "/v1/refresh"
	APIKeysEP      = "/v1/apikeys"
	ProjectsEP     = "/v1/projects"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerOption

type HandlerOption func(*handlerOptions)

HandlerOption allows users of the mock to configure specific endpoint handler behavior or override it entirely.

func RequireAuth added in v0.3.0

func RequireAuth() HandlerOption

Return a 401 response if the request is not authenticated

func UseError added in v0.3.0

func UseError(err string) HandlerOption

Configure a basic error reply to be returned by the handler

func UseHandler

func UseHandler(f http.HandlerFunc) HandlerOption

Use the given handler, overriding all other options

func UseJSONFixture

func UseJSONFixture(fixture interface{}) HandlerOption

Configure a JSON fixture to be returned by the handler

func UseStatus

func UseStatus(status int) HandlerOption

Configure the status code to be returned by the handler

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server embeds an httptest Server and provides additional methods for configuring mock responses and counting requests. By default handlers will panic, it's the responsibility of the test writer to configure the behavior of each handler that will be invoked by using the appropriate On* method and passing in the desired HandlerOption(s). If no HandlerOption is specified, the default behavior is to return a 200 OK response with an empty body.

func NewServer

func NewServer() (s *Server, err error)

NewServer creates and starts a new mock server for testing Quarterdeck interactions.

func (*Server) APIKeysCount

func (s *Server) APIKeysCount(param string) int

func (*Server) AuthenticateCount

func (s *Server) AuthenticateCount() int

func (*Server) Close

func (s *Server) Close()

func (*Server) LoginCount

func (s *Server) LoginCount() int

func (*Server) OnAPIKeys

func (s *Server) OnAPIKeys(param string, opts ...HandlerOption)

func (*Server) OnAuthenticate

func (s *Server) OnAuthenticate(opts ...HandlerOption)

func (*Server) OnLogin

func (s *Server) OnLogin(opts ...HandlerOption)

func (*Server) OnProjects added in v0.3.0

func (s *Server) OnProjects(opts ...HandlerOption)

func (*Server) OnRefresh

func (s *Server) OnRefresh(opts ...HandlerOption)

func (*Server) OnRegister

func (s *Server) OnRegister(opts ...HandlerOption)

func (*Server) OnStatus

func (s *Server) OnStatus(opts ...HandlerOption)

Endpoint handlers

func (*Server) ProjectsCount added in v0.3.0

func (s *Server) ProjectsCount() int

func (*Server) RefreshCount

func (s *Server) RefreshCount() int

func (*Server) RegisterCount

func (s *Server) RegisterCount() int

func (*Server) Reset added in v0.3.0

func (s *Server) Reset()

func (*Server) StatusCount

func (s *Server) StatusCount() int

Request counters

func (*Server) URL

func (s *Server) URL() string

Jump to

Keyboard shortcuts

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