testsuite

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const GO_NATIVE_TEST_SERVER_ENGINE = "go-test"

Variables

This section is empty.

Functions

func RevelTestHelper

func RevelTestHelper(m *testing.M, mode string, runner func(port int))

This function is a helper to allow a test to wrap the Revel server using this GoHttpTest server. Which simply transfers the request / response calls using a channel.

Types

type GoContext

type GoContext struct {
	Request   *GoRequest
	Response  *GoResponse
	WebSocket *GoWebSocket
}

func NewGOContext

func NewGOContext(instance *GoHttpServer) *GoContext

func (*GoContext) Destroy

func (c *GoContext) Destroy()

func (*GoContext) GetRequest

func (c *GoContext) GetRequest() revel.ServerRequest

func (*GoContext) GetResponse

func (c *GoContext) GetResponse() revel.ServerResponse

type GoCookie

type GoCookie http.Cookie

func (GoCookie) GetValue

func (r GoCookie) GetValue() string

type GoHeader

type GoHeader struct {
	Source interface{}
	// contains filtered or unexported fields
}

func (*GoHeader) Add

func (r *GoHeader) Add(key string, value string)

func (*GoHeader) Del

func (r *GoHeader) Del(key string)

func (*GoHeader) Get

func (r *GoHeader) Get(key string) (value []string)

func (*GoHeader) GetCookie

func (r *GoHeader) GetCookie(key string) (value revel.ServerCookie, err error)

func (*GoHeader) GetKeys added in v0.21.0

func (r *GoHeader) GetKeys() (value []string)

Returns list of header keys.

func (*GoHeader) Set

func (r *GoHeader) Set(key string, value string)

func (*GoHeader) SetCookie

func (r *GoHeader) SetCookie(cookie string)

func (*GoHeader) SetStatus

func (r *GoHeader) SetStatus(statusCode int)

type GoHttpServer

type GoHttpServer struct {
	Server           *http.Server      // Although unused this is here just to support possible code requests
	ServerInit       *revel.EngineInit // The intiialization data
	MaxMultipartSize int64
	TestChannel      chan *TestRequest
	StartedChan      chan bool
}

func (*GoHttpServer) Engine

func (g *GoHttpServer) Engine() interface{}

func (*GoHttpServer) Event

func (g *GoHttpServer) Event(event revel.Event, args interface{}) revel.EventResponse

func (*GoHttpServer) Handle

func (g *GoHttpServer) Handle(w http.ResponseWriter, r *http.Request)

func (*GoHttpServer) Init

func (g *GoHttpServer) Init(init *revel.EngineInit)

func (*GoHttpServer) Name

func (g *GoHttpServer) Name() string

func (*GoHttpServer) Start

func (g *GoHttpServer) Start()

The server is started and continues to listen on the TestChannel until it is ended.

func (*GoHttpServer) Stats

func (g *GoHttpServer) Stats() map[string]interface{}

type GoMultipartForm

type GoMultipartForm struct {
	Form *multipart.Form
}

func (*GoMultipartForm) GetFiles

func (f *GoMultipartForm) GetFiles() map[string][]*multipart.FileHeader

func (*GoMultipartForm) GetValues

func (f *GoMultipartForm) GetValues() url.Values

func (*GoMultipartForm) RemoveAll

func (f *GoMultipartForm) RemoveAll() error

type GoRequest

type GoRequest struct {
	Original        *http.Request
	FormParsed      bool
	MultiFormParsed bool
	WebSocket       *websocket.Conn
	ParsedForm      *GoMultipartForm
	Goheader        *GoHeader
	Engine          *GoHttpServer
}

func (*GoRequest) Destroy

func (r *GoRequest) Destroy()

func (*GoRequest) Get

func (r *GoRequest) Get(key int) (value interface{}, err error)

func (*GoRequest) GetForm

func (r *GoRequest) GetForm() (url.Values, error)

func (*GoRequest) GetHeader

func (r *GoRequest) GetHeader() revel.ServerHeader

func (*GoRequest) GetMultipartForm

func (r *GoRequest) GetMultipartForm() (revel.ServerMultipartForm, error)

func (*GoRequest) GetRaw

func (r *GoRequest) GetRaw() interface{}

func (*GoRequest) Set

func (r *GoRequest) Set(key int, value interface{}) bool

func (*GoRequest) SetRequest

func (r *GoRequest) SetRequest(req *http.Request)

type GoResponse

type GoResponse struct {
	Original http.ResponseWriter
	Goheader *GoHeader
	Writer   io.Writer
	Request  *GoRequest
	Engine   *GoHttpServer
}

func (*GoResponse) Destroy

func (r *GoResponse) Destroy()

func (*GoResponse) Get

func (r *GoResponse) Get(key int) (value interface{}, err error)

func (*GoResponse) GetRaw

func (r *GoResponse) GetRaw() interface{}

func (*GoResponse) Header

func (r *GoResponse) Header() revel.ServerHeader

func (*GoResponse) Set

func (r *GoResponse) Set(key int, value interface{}) (set bool)

func (*GoResponse) SetResponse

func (r *GoResponse) SetResponse(w http.ResponseWriter)

func (*GoResponse) SetWriter

func (r *GoResponse) SetWriter(writer io.Writer)

func (*GoResponse) WriteStream

func (r *GoResponse) WriteStream(name string, contentlen int64, modtime time.Time, reader io.Reader) error

type GoWebSocket

type GoWebSocket struct {
	Conn *websocket.Conn
	GoResponse
}

func (*GoWebSocket) MessageReceiveJSON

func (g *GoWebSocket) MessageReceiveJSON(v interface{}) error

func (*GoWebSocket) MessageSendJSON

func (g *GoWebSocket) MessageSendJSON(v interface{}) error

type TestRequest

type TestRequest struct {
	*http.Request

	Sent bool
	// contains filtered or unexported fields
}

func (*TestRequest) MakeRequest

func (r *TestRequest) MakeRequest() *TestRequest

MakeRequest issues any request and read the response. If successful, the caller may examine the Response and ResponseBody properties. You will need to manage session / cookie data manually.

func (*TestRequest) Send

func (r *TestRequest) Send() *TestRequest

Send issues any request and reads the response. If successful, the caller may examine the Response and ResponseBody properties. Session data will be added to the request cookies for you.

type TestSuite

type TestSuite struct {
	Response        *httptest.ResponseRecorder // The response recorder
	ResponseChannel chan bool                  // The response channel
	Session         session.Session            // The session
	SessionEngine   revel.SessionEngine        // The session engine
	Sent            bool                       // True if sent
	T               *testing.T                 // The test to handle any errors
	Client          *http.Client               // The client to extract the cookie data
}

TestSuite container.

func NewTestSuite

func NewTestSuite(t *testing.T) *TestSuite

Start a new request, with a new session.

func NewTestSuiteEngine added in v0.21.0

func NewTestSuiteEngine(engine revel.SessionEngine, t *testing.T) *TestSuite

Define a new test suite with a custom session engine.

func (*TestSuite) Assert

func (t *TestSuite) Assert(exp bool)

func (*TestSuite) AssertContains

func (t *TestSuite) AssertContains(s string)

AssertContains asserts that the response contains the given string.

func (*TestSuite) AssertContainsRegex

func (t *TestSuite) AssertContainsRegex(regex string)

AssertContainsRegex asserts that the response matches the given regular expression.

func (*TestSuite) AssertContentType

func (t *TestSuite) AssertContentType(contentType string)

func (*TestSuite) AssertEqual

func (t *TestSuite) AssertEqual(expected, actual interface{})

func (*TestSuite) AssertHeader

func (t *TestSuite) AssertHeader(name, value string)

func (*TestSuite) AssertNotContains

func (t *TestSuite) AssertNotContains(s string)

AssertNotContains asserts that the response does not contain the given string.

func (*TestSuite) AssertNotEqual

func (t *TestSuite) AssertNotEqual(expected, actual interface{})

func (*TestSuite) AssertNotFound

func (t *TestSuite) AssertNotFound()

func (*TestSuite) AssertOk

func (t *TestSuite) AssertOk()

func (*TestSuite) AssertStatus

func (t *TestSuite) AssertStatus(status int)

func (*TestSuite) Assertf

func (t *TestSuite) Assertf(exp bool, formatStr string, args ...interface{})

func (*TestSuite) BaseUrl

func (t *TestSuite) BaseUrl() string

BaseUrl returns the base http/https URL of the server, e.g. "http://127.0.0.1:8557". The scheme is set to https if http.ssl is set to true in the configuration file.

func (*TestSuite) Delete

func (t *TestSuite) Delete(path string)

Delete issues a DELETE request to the given path and stores the result in Response and ResponseBody.

func (*TestSuite) DeleteCustom

func (t *TestSuite) DeleteCustom(uri string) *TestRequest

DeleteCustom returns a DELETE request to the given URI in a form of its wrapper.

func (*TestSuite) Get

func (t *TestSuite) Get(path string) *TestSuite

Get issues a GET request to the given path and stores the result in Response and ResponseBody.

func (*TestSuite) GetCustom

func (t *TestSuite) GetCustom(uri string) *TestRequest

GetCustom returns a GET request to the given URI in a form of its wrapper.

func (*TestSuite) Host

func (t *TestSuite) Host() string

Host returns the address and port of the server, e.g. "127.0.0.1:8557".

func (*TestSuite) NewTestRequest

func (t *TestSuite) NewTestRequest(req *http.Request) *TestRequest

NewTestRequest returns an initialized *TestRequest. It is used for extending testsuite package making it possible to define own methods. Example:

type MyTestSuite struct {
	testing.TestSuite
}

func (t *MyTestSuite) PutFormCustom(...) {
	req := http.NewRequest(...)
	...
	return t.NewTestRequest(req)
}

func (*TestSuite) Patch

func (t *TestSuite) Patch(path string, contentType string, reader io.Reader) *TestSuite

Patch issues a PATCH request to the given path, sending the given Content-Type and data, and stores the result in Response and ResponseBody. "data" may be nil.

func (*TestSuite) PatchCustom

func (t *TestSuite) PatchCustom(uri string, contentType string, reader io.Reader) *TestRequest

PatchCustom returns a PATCH request to the given URI with specified Content-Type and data in a form of wrapper. "data" may be nil.

func (*TestSuite) Post

func (t *TestSuite) Post(path string, contentType string, reader io.Reader) *TestSuite

Post issues a POST request to the given path, sending the given Content-Type and data, storing the result in Response and ResponseBody. "data" may be nil.

func (*TestSuite) PostCustom

func (t *TestSuite) PostCustom(uri string, contentType string, reader io.Reader) *TestRequest

PostCustom returns a POST request to the given URI with specified Content-Type and data in a form of wrapper. "data" may be nil.

func (*TestSuite) PostFile

func (t *TestSuite) PostFile(path string, params url.Values, filePaths url.Values) *TestSuite

PostFile issues a multipart request to the given path sending given params and files, and stores the result in Response and ResponseBody.

func (*TestSuite) PostFileCustom

func (t *TestSuite) PostFileCustom(uri string, params url.Values, filePaths url.Values) *TestRequest

PostFileCustom returns a multipart request to the given URI in a form of its wrapper with the given params and files.

func (*TestSuite) PostForm

func (t *TestSuite) PostForm(path string, data url.Values) *TestSuite

PostForm issues a POST request to the given path as a form post of the given key and values, and stores the result in Response and ResponseBody.

func (*TestSuite) PostFormCustom

func (t *TestSuite) PostFormCustom(uri string, data url.Values) *TestRequest

PostFormCustom returns a POST request to the given URI as a form post of the given key and values. The request is in a form of TestRequest wrapper.

func (*TestSuite) Put

func (t *TestSuite) Put(path string, contentType string, reader io.Reader)

Put issues a PUT request to the given path, sending the given Content-Type and data, storing the result in Response and ResponseBody. "data" may be nil.

func (*TestSuite) PutCustom

func (t *TestSuite) PutCustom(uri string, contentType string, reader io.Reader) *TestRequest

PutCustom returns a PUT request to the given URI with specified Content-Type and data in a form of wrapper. "data" may be nil.

func (*TestSuite) PutForm

func (t *TestSuite) PutForm(path string, data url.Values) *TestSuite

PutForm issues a PUT request to the given path as a form put of the given key and values, and stores the result in Response and ResponseBody.

func (*TestSuite) PutFormCustom

func (t *TestSuite) PutFormCustom(uri string, data url.Values) *TestRequest

PutFormCustom returns a PUT request to the given URI as a form put of the given key and values. The request is in a form of TestRequest wrapper.

func (*TestSuite) WebSocket

func (t *TestSuite) WebSocket(path string) *websocket.Conn

WebSocket creates a websocket connection to the given path and returns it.

func (*TestSuite) WebSocketUrl

func (t *TestSuite) WebSocketUrl() string

WebSocketUrl returns the base websocket URL of the server, e.g. "ws://127.0.0.1:8557"

Jump to

Keyboard shortcuts

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