httpmockserver

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 14 Imported by: 0

README

Go Report Card GitHub license

HTTP Mock Server for golang

HTTP Mock Server provides an easy way to mock external http resources instead mocking your own code in system tests.

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IncomingRequest

type IncomingRequest struct {
	R    *http.Request
	Body []byte
}

type MockResponse

type MockResponse struct {
	Code    int
	Headers map[string]string
	Body    []byte
}

type MockServer

type MockServer struct {
	// contains filtered or unexported fields
}

func New

func New(t *testing.T) *MockServer

func NewWithOpts added in v0.2.0

func NewWithOpts(t *testing.T, opts Opts) *MockServer

func (*MockServer) DEFAULT added in v0.2.0

func (s *MockServer) DEFAULT() RequestExpectation

func (*MockServer) EVERY

func (s *MockServer) EVERY() RequestExpectation

TODO: response expectation makes no sense here

func (*MockServer) EXPECT

func (s *MockServer) EXPECT() RequestExpectation

func (*MockServer) Finish

func (s *MockServer) Finish()

func (*MockServer) ServeHTTP

func (s *MockServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MockServer) Shutdown

func (s *MockServer) Shutdown()

func (*MockServer) URL added in v0.2.0

func (s *MockServer) URL() string

type Opts added in v0.2.0

type Opts struct {
	Port   string
	UseSSL bool
	Cert   io.Reader
	Key    io.Reader
}

type RequestExpectation

type RequestExpectation interface {
	AnyRequest() RequestExpectation

	AnyTimes() RequestExpectation
	Times(n int) RequestExpectation
	MinTimes(n int) RequestExpectation
	MaxTimes(n int) RequestExpectation

	Request(method string, path string) RequestExpectation
	Method(method string) RequestExpectation
	Path(path string) RequestExpectation
	PathRegex(pathRegex string) RequestExpectation

	GET() RequestExpectation
	POST() RequestExpectation
	PUT() RequestExpectation
	DELETE() RequestExpectation

	Get(path string) RequestExpectation
	Post(path string) RequestExpectation
	Put(path string) RequestExpectation
	Delete(path string) RequestExpectation

	Header(key, value string) RequestExpectation
	Headers(map[string]string) RequestExpectation
	FormParameter(key, value string) RequestExpectation
	FormParameters(map[string]string) RequestExpectation

	BasicAuth(user, password string) RequestExpectation

	Custom(validation RequestValidationFunc, description string) RequestExpectation

	JsonBody(object interface{}) RequestExpectation
	StringBody(body string) RequestExpectation
	Body(body []byte) RequestExpectation
	BodyFunc(func(body []byte) error) RequestExpectation

	// switch to responseExpectations
	Response(code int) ResponseExpectation
}

type RequestValidationFunc

type RequestValidationFunc func(r *IncomingRequest) error

type ResponseExpectation

type ResponseExpectation interface {
	Header(key, value string) ResponseExpectation
	Headers(headers map[string]string) ResponseExpectation
	StringBody(body string) ResponseExpectation
	JsonBody(object interface{}) ResponseExpectation
	Body(data []byte) ResponseExpectation
}

Jump to

Keyboard shortcuts

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