test

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFixture

func LoadFixture(name string) ([]byte, error)

LoadFixture loads the content of a fixture file.

func MakeMockClient

func MakeMockClient(mockOptions SimpleMockOptions) *misskey.Client

MakeMockClient creates a new Client with SimpleMockOptions.

func Must

func Must(content []byte, err error) []byte

Must be content. Basically go and panic if error happened.

func NewMockResponse

func NewMockResponse(code int, content []byte, err error) (*http.Response, error)

NewMockResponse creates a new mock response.

func ValidateRequests

func ValidateRequests(t *testing.T, invalidRequests []core.BaseRequest, validRequests []core.BaseRequest)

ValidateRequests validates requests with their Validate function and check if error occurred or not.

Types

type BadReadCloser

type BadReadCloser struct{}

BadReadCloser is a basic ReadCloser with error. The only purpose is to test what is the connection dropped or something.

func (BadReadCloser) Close

func (r BadReadCloser) Close() error

Close the reader.

func (BadReadCloser) Read

func (r BadReadCloser) Read(c []byte) (int, error)

type FixtureFileNotFound

type FixtureFileNotFound struct {
	Path string
	Name string
}

FixtureFileNotFound occurs when the requested fixture file does not exist.

func (FixtureFileNotFound) Error

func (e FixtureFileNotFound) Error() string

type MockBody

type MockBody struct {
	*bytes.Reader
}

MockBody is a bulletproof ReadCloser.

func (MockBody) Close

func (m MockBody) Close() error

Close the reader.

type MockHTTPClient

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

MockHTTPClient is a very basic mock implementation of the HTTPClient.

func NewMockHTTPClient

func NewMockHTTPClient() *MockHTTPClient

NewMockHTTPClient boostraps a new MockHTTPClient.

func SimpleMockEndpoint

func SimpleMockEndpoint(options *SimpleMockOptions) *MockHTTPClient

SimpleMockEndpoint creates a simple MockHTTPClient that returns with an error if it was not able to pasre the request or returns with the content of the provided fixture file.

func (*MockHTTPClient) Do

func (c *MockHTTPClient) Do(request *http.Request) (*http.Response, error)

Do is the real requirement to be an HTTPClient.

func (*MockHTTPClient) MockRequest

func (c *MockHTTPClient) MockRequest(path string, handler MockRequestHandler)

MockRequest registers a new endpoint.

type MockRequestHandler

type MockRequestHandler func(request *http.Request) (*http.Response, error)

MockRequestHandler is just an alias for the function signature used to hanle mock requests.

type MockType added in v1.0.1

type MockType string

MockType defined what type of request it expects.

const (
	JSONMockType   MockType = "json"
	IgnoreMockType MockType = "ignore"
	FormMockType   MockType = "form"
)

Type of Mock requests.

type SimpleMockOptions

type SimpleMockOptions struct {
	Endpoint         string
	ResponseFile     string
	ResponseFileFunc func(interface{}) string
	RequestData      interface{}
	StatusCode       int
	Type             MockType
}

SimpleMockOptions is the parameter list for SimpleMockEndpoint.

Jump to

Keyboard shortcuts

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