testing

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: 18 Imported by: 387

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestSuites []interface{} // Array of structs that embed TestSuite

This is populated by the generated code in the run/run/go file.

Functions

This section is empty.

Types

type TestRequest

type TestRequest struct {
	*http.Request
	// contains filtered or unexported fields
}

func (*TestRequest) MakeRequest

func (r *TestRequest) MakeRequest()

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()

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

type TestSuite

type TestSuite struct {
	Client        *http.Client
	Response      *http.Response
	ResponseBody  []byte
	Session       session.Session
	SessionEngine revel.SessionEngine
}

func NewTestSuite

func NewTestSuite() TestSuite

NewTestSuite returns an initialized TestSuite ready for use. It is invoked by the test harness to initialize the embedded field in application tests.

func NewTestSuiteEngine added in v0.21.0

func NewTestSuiteEngine(engine revel.SessionEngine) 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)

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)

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)

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)

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)

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 added in v0.13.0

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

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 added in v0.13.0

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