Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithPort ¶ added in v1.1.1
func WithPort(port int) func(*FakeService)
Types ¶
type Endpoint ¶
type Endpoint struct {
Path string
Response string
StatusCode int
Methods []string
ContentType string
Headers Headers
Handler func(*gin.Context)
// FailureRatePercent - allows you to specify the probability
// of failure for your Endpoint. I.e. 0.8 represents and 80%
// chance you'll be met with a 500 response.
FailureRatePercent int
// FailureHandler - allows you to define a custom failure
// handler so that you can model how your upstream dependencies
// could fail.
FailureHandler func(*gin.Context)
// Expectation - it can be handy to specify assertions
// in the context of the tests you are developing. This
// will allow you to make assertions on the request that
// eventually makes it to your fake.
Expectation func(*http.Request)
// contains filtered or unexported fields
}
Endpoint - represents an Endpoint defined under the context of a FakeService.
type FakeService ¶
type FakeService struct {
Endpoints []*Endpoint
Port int
BaseURL string
// contains filtered or unexported fields
}
FakeService - the core of this lib. features a ref to a gin.Engine and a slice of Endpoints. BaseURL is an exposed field which is set at the point at which the Run method is called.
func New ¶ added in v1.1.0
func New(opts ...func(*FakeService)) *FakeService
NewFakeHTTP - a constructor that spins up a new reference to a FakeService.
func (*FakeService) Endpoint ¶ added in v1.1.0
func (f *FakeService) Endpoint(e *Endpoint) *FakeService
Endpoint - registers a new endpoint on the fake service. This will set some sensible defaults should the Endpoint not have them explicitly defined. For example, we default to HTTP 200 statuses and a Content-Type of 'application/json'. Whenever said endpoint is called, we ensure that we record the call and increment the `calls` field.
func (*FakeService) Run ¶
func (f *FakeService) Run(t *testing.T) *FakeService
Run - starts up the fake service. This creates a custom net listener which then replaces the testserver listener. This was due to communication issues between docker containers originally, however, this argument may no longer hold water.
func (*FakeService) TidyUp ¶
func (f *FakeService) TidyUp(t *testing.T)
TidyUp - this method ranges over all of the endpoints defined under this FakeService and ensures that each of them have been called at least once. If the call count is 0, then this will fail the test that depends on this fake service.