service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2017 License: BSD-3-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParameterNotPresented = errors.New("parameter not presented")
)

Functions

func GetClientIP

func GetClientIP(req *http.Request) string

Types

type Endpoint

type Endpoint struct {
	Method   string
	Route    string
	Policy   Policy
	Pipeline Pipeline
}

type EndpointsInvocation

type EndpointsInvocation struct {
	Results struct {
		Ident102 []Endpoint
	}
}

EndpointsInvocation represents a single call of FakeService.Endpoints

type FakeResponse

type FakeResponse struct {
	StatusCodeHook func() int
	HeaderHook     func() http.Header
	TrailerHook    func() http.Header
	SerializeHook  func(io.Writer) error

	StatusCodeCalls []*StatusCodeInvocation
	HeaderCalls     []*HeaderInvocation
	TrailerCalls    []*TrailerInvocation
	SerializeCalls  []*SerializeInvocation
}

FakeResponse is a mock implementation of Response for testing. Use it in your tests as in this example:

package example

func TestWithResponse(t *testing.T) {
	f := &service.FakeResponse{
		StatusCodeHook: func() (ident59 int) {
			// ensure parameters meet expections, signal errors using t, etc
			return
		},
	}

	// test code goes here ...

	// assert state of FakeStatusCode ...
	f.AssertStatusCodeCalledOnce(t)
}

Create anonymous function implementations for only those interface methods that should be called in the code under test. This will force a panic if any unexpected calls are made to FakeStatusCode.

func NewFakeResponseDefaultError

func NewFakeResponseDefaultError(t *testing.T) *FakeResponse

NewFakeResponseDefaultError returns an instance of FakeResponse with all hooks configured to call t.Error

func NewFakeResponseDefaultFatal

func NewFakeResponseDefaultFatal(t *testing.T) *FakeResponse

NewFakeResponseDefaultFatal returns an instance of FakeResponse with all hooks configured to call t.Fatal

func NewFakeResponseDefaultPanic

func NewFakeResponseDefaultPanic() *FakeResponse

NewFakeResponseDefaultPanic returns an instance of FakeResponse with all hooks configured to panic

func (*FakeResponse) AssertHeaderCalled

func (f *FakeResponse) AssertHeaderCalled(t *testing.T)

AssertHeaderCalled calls t.Error if FakeResponse.Header was not called

func (*FakeResponse) AssertHeaderCalledN

func (f *FakeResponse) AssertHeaderCalledN(t *testing.T, n int)

AssertHeaderCalledN calls t.Error if FakeResponse.Header was called less than n times

func (*FakeResponse) AssertHeaderCalledOnce

func (f *FakeResponse) AssertHeaderCalledOnce(t *testing.T)

AssertHeaderCalledOnce calls t.Error if FakeResponse.Header was not called exactly once

func (*FakeResponse) AssertHeaderNotCalled

func (f *FakeResponse) AssertHeaderNotCalled(t *testing.T)

AssertHeaderNotCalled calls t.Error if FakeResponse.Header was called

func (*FakeResponse) AssertSerializeCalled

func (f *FakeResponse) AssertSerializeCalled(t *testing.T)

AssertSerializeCalled calls t.Error if FakeResponse.Serialize was not called

func (*FakeResponse) AssertSerializeCalledN

func (f *FakeResponse) AssertSerializeCalledN(t *testing.T, n int)

AssertSerializeCalledN calls t.Error if FakeResponse.Serialize was called less than n times

func (*FakeResponse) AssertSerializeCalledOnce

func (f *FakeResponse) AssertSerializeCalledOnce(t *testing.T)

AssertSerializeCalledOnce calls t.Error if FakeResponse.Serialize was not called exactly once

func (*FakeResponse) AssertSerializeCalledOnceWith

func (_f8 *FakeResponse) AssertSerializeCalledOnceWith(t *testing.T, ident62 io.Writer)

AssertSerializeCalledOnceWith calls t.Error if FakeResponse.Serialize was not called exactly once with the given values

func (*FakeResponse) AssertSerializeCalledWith

func (_f6 *FakeResponse) AssertSerializeCalledWith(t *testing.T, ident62 io.Writer)

AssertSerializeCalledWith calls t.Error if FakeResponse.Serialize was not called with the given values

func (*FakeResponse) AssertSerializeNotCalled

func (f *FakeResponse) AssertSerializeNotCalled(t *testing.T)

AssertSerializeNotCalled calls t.Error if FakeResponse.Serialize was called

func (*FakeResponse) AssertStatusCodeCalled

func (f *FakeResponse) AssertStatusCodeCalled(t *testing.T)

AssertStatusCodeCalled calls t.Error if FakeResponse.StatusCode was not called

func (*FakeResponse) AssertStatusCodeCalledN

func (f *FakeResponse) AssertStatusCodeCalledN(t *testing.T, n int)

AssertStatusCodeCalledN calls t.Error if FakeResponse.StatusCode was called less than n times

func (*FakeResponse) AssertStatusCodeCalledOnce

func (f *FakeResponse) AssertStatusCodeCalledOnce(t *testing.T)

AssertStatusCodeCalledOnce calls t.Error if FakeResponse.StatusCode was not called exactly once

func (*FakeResponse) AssertStatusCodeNotCalled

func (f *FakeResponse) AssertStatusCodeNotCalled(t *testing.T)

AssertStatusCodeNotCalled calls t.Error if FakeResponse.StatusCode was called

func (*FakeResponse) AssertTrailerCalled

func (f *FakeResponse) AssertTrailerCalled(t *testing.T)

AssertTrailerCalled calls t.Error if FakeResponse.Trailer was not called

func (*FakeResponse) AssertTrailerCalledN

func (f *FakeResponse) AssertTrailerCalledN(t *testing.T, n int)

AssertTrailerCalledN calls t.Error if FakeResponse.Trailer was called less than n times

func (*FakeResponse) AssertTrailerCalledOnce

func (f *FakeResponse) AssertTrailerCalledOnce(t *testing.T)

AssertTrailerCalledOnce calls t.Error if FakeResponse.Trailer was not called exactly once

func (*FakeResponse) AssertTrailerNotCalled

func (f *FakeResponse) AssertTrailerNotCalled(t *testing.T)

AssertTrailerNotCalled calls t.Error if FakeResponse.Trailer was called

func (*FakeResponse) Header

func (_f2 *FakeResponse) Header() (ident60 http.Header)

func (*FakeResponse) HeaderCalled

func (f *FakeResponse) HeaderCalled() bool

HeaderCalled returns true if FakeResponse.Header was called

func (*FakeResponse) HeaderCalledN

func (f *FakeResponse) HeaderCalledN(n int) bool

HeaderCalledN returns true if FakeResponse.Header was called at least n times

func (*FakeResponse) HeaderCalledOnce

func (f *FakeResponse) HeaderCalledOnce() bool

HeaderCalledOnce returns true if FakeResponse.Header was called exactly once

func (*FakeResponse) HeaderNotCalled

func (f *FakeResponse) HeaderNotCalled() bool

HeaderNotCalled returns true if FakeResponse.Header was not called

func (*FakeResponse) Serialize

func (_f4 *FakeResponse) Serialize(ident62 io.Writer) (ident63 error)

func (*FakeResponse) SerializeCalled

func (f *FakeResponse) SerializeCalled() bool

SerializeCalled returns true if FakeResponse.Serialize was called

func (*FakeResponse) SerializeCalledN

func (f *FakeResponse) SerializeCalledN(n int) bool

SerializeCalledN returns true if FakeResponse.Serialize was called at least n times

func (*FakeResponse) SerializeCalledOnce

func (f *FakeResponse) SerializeCalledOnce() bool

SerializeCalledOnce returns true if FakeResponse.Serialize was called exactly once

func (*FakeResponse) SerializeCalledOnceWith

func (_f7 *FakeResponse) SerializeCalledOnceWith(ident62 io.Writer) bool

SerializeCalledOnceWith returns true if FakeResponse.Serialize was called exactly once with the given values

func (*FakeResponse) SerializeCalledWith

func (_f5 *FakeResponse) SerializeCalledWith(ident62 io.Writer) (found bool)

SerializeCalledWith returns true if FakeResponse.Serialize was called with the given values

func (*FakeResponse) SerializeNotCalled

func (f *FakeResponse) SerializeNotCalled() bool

SerializeNotCalled returns true if FakeResponse.Serialize was not called

func (*FakeResponse) SerializeResultsForCall

func (_f9 *FakeResponse) SerializeResultsForCall(ident62 io.Writer) (ident63 error, found bool)

SerializeResultsForCall returns the result values for the first call to FakeResponse.Serialize with the given values

func (*FakeResponse) StatusCode

func (_f1 *FakeResponse) StatusCode() (ident59 int)

func (*FakeResponse) StatusCodeCalled

func (f *FakeResponse) StatusCodeCalled() bool

StatusCodeCalled returns true if FakeResponse.StatusCode was called

func (*FakeResponse) StatusCodeCalledN

func (f *FakeResponse) StatusCodeCalledN(n int) bool

StatusCodeCalledN returns true if FakeResponse.StatusCode was called at least n times

func (*FakeResponse) StatusCodeCalledOnce

func (f *FakeResponse) StatusCodeCalledOnce() bool

StatusCodeCalledOnce returns true if FakeResponse.StatusCode was called exactly once

func (*FakeResponse) StatusCodeNotCalled

func (f *FakeResponse) StatusCodeNotCalled() bool

StatusCodeNotCalled returns true if FakeResponse.StatusCode was not called

func (*FakeResponse) Trailer

func (_f3 *FakeResponse) Trailer() (ident61 http.Header)

func (*FakeResponse) TrailerCalled

func (f *FakeResponse) TrailerCalled() bool

TrailerCalled returns true if FakeResponse.Trailer was called

func (*FakeResponse) TrailerCalledN

func (f *FakeResponse) TrailerCalledN(n int) bool

TrailerCalledN returns true if FakeResponse.Trailer was called at least n times

func (*FakeResponse) TrailerCalledOnce

func (f *FakeResponse) TrailerCalledOnce() bool

TrailerCalledOnce returns true if FakeResponse.Trailer was called exactly once

func (*FakeResponse) TrailerNotCalled

func (f *FakeResponse) TrailerNotCalled() bool

TrailerNotCalled returns true if FakeResponse.Trailer was not called

type FakeService

type FakeService struct {
	NameHook      func() string
	EndpointsHook func() []Endpoint

	NameCalls      []*NameInvocation
	EndpointsCalls []*EndpointsInvocation
}

FakeService is a mock implementation of Service for testing. Use it in your tests as in this example:

package example

func TestWithService(t *testing.T) {
	f := &service.FakeService{
		NameHook: func() (ident101 string) {
			// ensure parameters meet expections, signal errors using t, etc
			return
		},
	}

	// test code goes here ...

	// assert state of FakeName ...
	f.AssertNameCalledOnce(t)
}

Create anonymous function implementations for only those interface methods that should be called in the code under test. This will force a panic if any unexpected calls are made to FakeName.

func NewFakeServiceDefaultError

func NewFakeServiceDefaultError(t *testing.T) *FakeService

NewFakeServiceDefaultError returns an instance of FakeService with all hooks configured to call t.Error

func NewFakeServiceDefaultFatal

func NewFakeServiceDefaultFatal(t *testing.T) *FakeService

NewFakeServiceDefaultFatal returns an instance of FakeService with all hooks configured to call t.Fatal

func NewFakeServiceDefaultPanic

func NewFakeServiceDefaultPanic() *FakeService

NewFakeServiceDefaultPanic returns an instance of FakeService with all hooks configured to panic

func (*FakeService) AssertEndpointsCalled

func (f *FakeService) AssertEndpointsCalled(t *testing.T)

AssertEndpointsCalled calls t.Error if FakeService.Endpoints was not called

func (*FakeService) AssertEndpointsCalledN

func (f *FakeService) AssertEndpointsCalledN(t *testing.T, n int)

AssertEndpointsCalledN calls t.Error if FakeService.Endpoints was called less than n times

func (*FakeService) AssertEndpointsCalledOnce

func (f *FakeService) AssertEndpointsCalledOnce(t *testing.T)

AssertEndpointsCalledOnce calls t.Error if FakeService.Endpoints was not called exactly once

func (*FakeService) AssertEndpointsNotCalled

func (f *FakeService) AssertEndpointsNotCalled(t *testing.T)

AssertEndpointsNotCalled calls t.Error if FakeService.Endpoints was called

func (*FakeService) AssertNameCalled

func (f *FakeService) AssertNameCalled(t *testing.T)

AssertNameCalled calls t.Error if FakeService.Name was not called

func (*FakeService) AssertNameCalledN

func (f *FakeService) AssertNameCalledN(t *testing.T, n int)

AssertNameCalledN calls t.Error if FakeService.Name was called less than n times

func (*FakeService) AssertNameCalledOnce

func (f *FakeService) AssertNameCalledOnce(t *testing.T)

AssertNameCalledOnce calls t.Error if FakeService.Name was not called exactly once

func (*FakeService) AssertNameNotCalled

func (f *FakeService) AssertNameNotCalled(t *testing.T)

AssertNameNotCalled calls t.Error if FakeService.Name was called

func (*FakeService) Endpoints

func (_f2 *FakeService) Endpoints() (ident102 []Endpoint)

func (*FakeService) EndpointsCalled

func (f *FakeService) EndpointsCalled() bool

EndpointsCalled returns true if FakeService.Endpoints was called

func (*FakeService) EndpointsCalledN

func (f *FakeService) EndpointsCalledN(n int) bool

EndpointsCalledN returns true if FakeService.Endpoints was called at least n times

func (*FakeService) EndpointsCalledOnce

func (f *FakeService) EndpointsCalledOnce() bool

EndpointsCalledOnce returns true if FakeService.Endpoints was called exactly once

func (*FakeService) EndpointsNotCalled

func (f *FakeService) EndpointsNotCalled() bool

EndpointsNotCalled returns true if FakeService.Endpoints was not called

func (*FakeService) Name

func (_f1 *FakeService) Name() (ident101 string)

func (*FakeService) NameCalled

func (f *FakeService) NameCalled() bool

NameCalled returns true if FakeService.Name was called

func (*FakeService) NameCalledN

func (f *FakeService) NameCalledN(n int) bool

NameCalledN returns true if FakeService.Name was called at least n times

func (*FakeService) NameCalledOnce

func (f *FakeService) NameCalledOnce() bool

NameCalledOnce returns true if FakeService.Name was called exactly once

func (*FakeService) NameNotCalled

func (f *FakeService) NameNotCalled() bool

NameNotCalled returns true if FakeService.Name was not called

type Handler

type Handler func(context.Context, *Request) Response

type HeaderInvocation

type HeaderInvocation struct {
	Results struct {
		Ident60 http.Header
	}
}

HeaderInvocation represents a single call of FakeResponse.Header

type NameInvocation

type NameInvocation struct {
	Results struct {
		Ident101 string
	}
}

NameInvocation represents a single call of FakeService.Name

type Pipeline

type Pipeline []Handler

type Policy

type Policy struct {
	AllowUnknownQueryParameters   bool          // will unknown query parameters be silently ignored?
	AllowMalformedQueryParameters bool          // will malformed query parameter pairs be silently ignored?
	CustomMalformedRequestStatus  int           // this status code will be returned instead of 400 on malformed requests
	RequestBudget                 time.Duration // the time budget for requests to the endpoint
	GenerateRequestID             bool          // should a request id be generated automatically?
}

Policy controls the behavior of per-endpoint request processing before control is passed to the handler.

type Request

type Request struct {
	*http.Request
	PathArgs    url.Values
	QueryParams url.Values
}

func (*Request) GenerateID

func (r *Request) GenerateID() string

func (*Request) PathArg

func (r *Request) PathArg(name string) (string, bool)

func (*Request) PathArgInt

func (r *Request) PathArgInt(name string) (int, error)

func (*Request) QueryParam

func (r *Request) QueryParam(name string) (string, bool)

func (*Request) QueryParamBool

func (r *Request) QueryParamBool(name string) (bool, bool)

func (*Request) QueryParamExists

func (r *Request) QueryParamExists(name string) bool

func (*Request) QueryParamInt

func (r *Request) QueryParamInt(name string) (int, error)

func (*Request) QueryParamUint

func (r *Request) QueryParamUint(name string) (uint, error)

type Response

type Response interface {
	StatusCode() int
	Header() http.Header
	Trailer() http.Header
	Serialize(io.Writer) error
}

func NewOK

func NewOK(body json.Marshaler) Response

type SerializeInvocation

type SerializeInvocation struct {
	Parameters struct {
		Ident62 io.Writer
	}
	Results struct {
		Ident63 error
	}
}

SerializeInvocation represents a single call of FakeResponse.Serialize

type Service

type Service interface {
	Name() string
	Endpoints() []Endpoint
}

type StatusCodeInvocation

type StatusCodeInvocation struct {
	Results struct {
		Ident59 int
	}
}

StatusCodeInvocation represents a single call of FakeResponse.StatusCode

type TrailerInvocation

type TrailerInvocation struct {
	Results struct {
		Ident61 http.Header
	}
}

TrailerInvocation represents a single call of FakeResponse.Trailer

Jump to

Keyboard shortcuts

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