tests

package
v0.0.0-...-d57bbc6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustReadFile

func MustReadFile(filename string) (content []byte)

func NewHTTPTestServer

func NewHTTPTestServer(route Route) (*httptest.Server, func())

NewHTTPTestServer creates a server with default 404 content response return logic. One can configure server with route objects and responses that should be returned on the certain urls (like ^/artifactory/.*$ will be matched with all urls that starts with /artifactory/)

func OpenFile

func OpenFile(filename string) (*os.File, func())

OpenFile opens a file and returns its descriptor and callback function which closes file. callback function has to be used in defer instruction

Types

type HTTPBuffer

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

HTTPBuffer is a http in-memory buffer used for testing

func NewHTTPBuffer

func NewHTTPBuffer() *HTTPBuffer

NewHTTPBuffer creates a new buffer object.

func (*HTTPBuffer) Header

func (h *HTTPBuffer) Header() http.Header

Header implements http.ResponseWriter interface.

func (*HTTPBuffer) String

func (h *HTTPBuffer) String() string

String implements fmt.Stringer interface.

func (*HTTPBuffer) Write

func (h *HTTPBuffer) Write(p []byte) (n int, err error)

Write implements http.ResponseWriter interface.

func (*HTTPBuffer) WriteHeader

func (h *HTTPBuffer) WriteHeader(statusCode int)

WriteHeader implements http.ResponseWriter interface.

type Options

type Options struct {
	Status int
}

Options sets different response options to set in http testing responses

type Response

type Response struct {
	Options  *Options
	Contents []byte
}

Response is used for a testing response

type Route

type Route map[string]*Response

Route is a map of regular expression-like strings and response objects basically keys of route matches over regular expression with request url path and if match occurs, response will be used. A tiny plain and simple routing based on urls

Jump to

Keyboard shortcuts

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