gotest

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 9 Imported by: 0

README

gotest

Has useful functions and mocks to help the tests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanURI

func CleanURI(name string) string

CleanURI - cleans and validates the URI

func CopyHeaders

func CopyHeaders(source http.Header, dest http.Header)

CopyHeaders - copy all the headers

Types

type HTTPServer

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

HTTPServer - the server listening for HTTP requests

func CreateNewTestHTTPServer

func CreateNewTestHTTPServer(testServerHost string, testServerPort int, responses []ResponseData) *HTTPServer

CreateNewTestHTTPServer - creates a new server

func NewHTTPServer

func NewHTTPServer(host string, port, channelSize int, responses []ResponseData) (*HTTPServer, error)

NewHTTPServer - creates a new HTTP listener server

func (*HTTPServer) Close

func (hl *HTTPServer) Close()

Close - closes this server

func (*HTTPServer) RequestChannel

func (hl *HTTPServer) RequestChannel() <-chan *RequestData

RequestChannel - reads from the request channel

type RequestData

type RequestData struct {
	URI     string
	Body    string
	Method  string
	Headers http.Header
	Date    time.Time
}

RequestData - the request data sent to the server

func WaitForHTTPServerRequest

func WaitForHTTPServerRequest(server *HTTPServer, waitFor, maxRequestTimeout time.Duration) *RequestData

WaitForHTTPServerRequest - wait until timeout or for the server sets the request in the channel

type ResponseData

type ResponseData struct {
	RequestData
	Status int
}

ResponseData - the expected response data for each configured URI

func DoRequest

func DoRequest(testServerHost string, testServerPort int, request *RequestData) *ResponseData

DoRequest - does a request

func ParseResponse

func ParseResponse(res *http.Response, reqDate time.Time) (*ResponseData, error)

ParseResponse - parses the response using the local struct as result

Jump to

Keyboard shortcuts

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