testutil

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExpected = fmt.Errorf("call is not expected")

ErrNotExpected is expectation error.

Functions

func WithSDK

func WithSDK(t *testing.T, f func(*testing.T, *api.VK, *TestCase))

WithSDK calls CreateSDK and passes result to callback. Fails if not ExpectationsWereMet after f parameter call.

Types

type Expectation

type Expectation struct {
	Method        string
	Params        api.Params
	Response      api.Response
	ErrorResponse bool
	ErrorMessage  string
}

Expectation is VK API call expectation.

func NewExpectation

func NewExpectation(method string) *Expectation

NewExpectation creates new Expectation.

func (*Expectation) Fails

func (e *Expectation) Fails(fails bool) *Expectation

Fails marks API result as failed.

func (Expectation) Match

func (e Expectation) Match(method string, params ...api.Params) (bool, api.Response, error)

Match compares API call.

func (*Expectation) Returns

func (e *Expectation) Returns(response api.Response) *Expectation

Returns sets API call result.

func (*Expectation) ReturnsBytes

func (e *Expectation) ReturnsBytes(data []byte) *Expectation

ReturnsBytes sets API call result.

func (*Expectation) ReturnsBytesF

func (e *Expectation) ReturnsBytesF(f func() []byte) *Expectation

ReturnsBytesF sets API call result using function.

func (*Expectation) ReturnsF

func (e *Expectation) ReturnsF(f func() api.Response) *Expectation

ReturnsF sets API call result using function.

func (*Expectation) ReturnsJSON

func (e *Expectation) ReturnsJSON(v interface{}) *Expectation

ReturnsJSON sets API call result.

func (*Expectation) ReturnsJSONF

func (e *Expectation) ReturnsJSONF(f func() interface{}) *Expectation

ReturnsJSONF sets API call result using function.

func (*Expectation) WithError

func (e *Expectation) WithError(message string) *Expectation

WithError sets API call error. Calls Fails(true).

func (*Expectation) WithParams

func (e *Expectation) WithParams(params api.Params) *Expectation

WithParams sets expected params. If API call contains unexpected params, it wouldn't fail.

func (*Expectation) WithParamsF

func (e *Expectation) WithParamsF(f func() api.Params) *Expectation

WithParamsF sets expected params using function. If API call contains unexpected params, it wouldn't fail.

type Expectations

type Expectations []*Expectation

func (*Expectations) Pop

func (stack *Expectations) Pop() (result *Expectation, ok bool)

func (*Expectations) Push

func (stack *Expectations) Push(element *Expectation)

type TestCase

type TestCase struct {
	Expectations    Expectations
	T               *testing.T
	DefaultResponse api.Response
	// contains filtered or unexported fields
}

TestCase is VK SDK testcase.

func CreateSDK

func CreateSDK(t *testing.T) (*api.VK, *TestCase)

CreateSDK creates new testing VK SDK and TestCase.

func NewTestCase

func NewTestCase(t *testing.T) *TestCase

NewTestCase creates new TestCase.

func (*TestCase) AllowNotExpected

func (test *TestCase) AllowNotExpected()

AllowNotExpected allows not expected calls.

func (*TestCase) ExpectCall

func (test *TestCase) ExpectCall(method string) *Expectation

ExpectCall adds call expectation.

func (*TestCase) ExpectationsError added in v2.0.1

func (test *TestCase) ExpectationsError() error

ExpectationsError returns error if not all call expectation were met.

func (*TestCase) ExpectationsWereMet

func (test *TestCase) ExpectationsWereMet() error

ExpectationsWereMet checks that all call expectation were met. Calls T.Error(err).

func (*TestCase) Handler

func (test *TestCase) Handler() sdkutil.Handler

Handler is mocking VK SDK handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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