Documentation
¶
Index ¶
- type Matcher
- type MockServer
- func (ms *MockServer) AssertExpectations()
- func (ms *MockServer) AssertNotCalled(endpoint string)
- func (ms *MockServer) Delete(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Get(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Head(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Patch(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Port() int
- func (ms *MockServer) Post(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Put(pattern string, matchers ...Matcher) *Returner
- func (ms *MockServer) Router() chi.Router
- func (ms *MockServer) Server() *httptest.Server
- func (ms *MockServer) Start(t *testing.T)
- func (ms *MockServer) Teardown()
- func (ms *MockServer) URL() string
- type Option
- type Responder
- type Returner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockServer ¶
MockServer is an HTTP testing server designed for easy mocking of REST APIs.
func NewMockServer ¶
func NewMockServer(opts ...Option) *MockServer
NewMockServer creates a MockServer with the provided options.
func (*MockServer) AssertExpectations ¶
func (ms *MockServer) AssertExpectations()
AssertExpectations verifies that every registered endpoint was called at least once.
func (*MockServer) AssertNotCalled ¶
func (ms *MockServer) AssertNotCalled(endpoint string)
AssertNotCalled verifies that the given endpoint was never called.
func (*MockServer) Delete ¶
func (ms *MockServer) Delete(pattern string, matchers ...Matcher) *Returner
Delete creates a mock endpoint for a delete request.
func (*MockServer) Get ¶
func (ms *MockServer) Get(pattern string, matchers ...Matcher) *Returner
Get creates a mock endpoint for a get request.
func (*MockServer) Head ¶
func (ms *MockServer) Head(pattern string, matchers ...Matcher) *Returner
Head creates a mock endpoint for a head request.
func (*MockServer) Patch ¶
func (ms *MockServer) Patch(pattern string, matchers ...Matcher) *Returner
Patch creates a mock endpoint for a patch request.
func (*MockServer) Port ¶
func (ms *MockServer) Port() int
Port returns the TCP port where the MockServer is listening. It can be a statically configured port or a dynamic allocated one.
func (*MockServer) Post ¶
func (ms *MockServer) Post(pattern string, matchers ...Matcher) *Returner
Post creates a mock endpoint for a post request.
func (*MockServer) Put ¶
func (ms *MockServer) Put(pattern string, matchers ...Matcher) *Returner
Put creates a mock endpoint for a put request.
func (*MockServer) Router ¶
func (ms *MockServer) Router() chi.Router
Router exposes the internal chi.Router to allow configurations not supported by the helper methods.
func (*MockServer) Server ¶
func (ms *MockServer) Server() *httptest.Server
Server exposes the internal testing HTTP server.
func (*MockServer) Start ¶
func (ms *MockServer) Start(t *testing.T)
Start initializes the MockServer on a background goroutine.
Important: All endpoint mocks MUST be defined before calling this method.
func (*MockServer) Teardown ¶
func (ms *MockServer) Teardown()
Teardown stops the HTTP server.
Call this with a defer after starting the server.
func (*MockServer) URL ¶
func (ms *MockServer) URL() string
URL returns the MockServer URL. Value is http://127.0.0.1:<server port>
type Responder ¶
type Responder func(w http.ResponseWriter)
Responder configures a http.ResponseWriter to send data back.
func JSONFileBody ¶
JSONFileBody is a Responder that defines the response body as a JSON file.
func StatusCode ¶
StatusCode is a Responder that defines the response status code.