e2e

package
v0.330.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeKey = "Content-Type"
)
View Source
const (
	// DownstreamTimeout is only used for mocked downstreams, and is as small as possible to make the timeout tests
	// quicker, but give them time to actually succeed.
	DownstreamTimeout = time.Millisecond * 400
)

Variables

View Source
var IgnoreHeaders = []string{}

IgnoreHeaders is a list of headers that should be ignored during testing.

Functions

func ConfigToYamlData

func ConfigToYamlData(cfg interface{}, appCfgType reflect.Type) ([]byte, error)

func CreateServiceWithTestHooksPatched

func CreateServiceWithTestHooksPatched(createService interface{}, testHooks *core.Hooks) interface{}

CreateServiceWithTestHooksPatched will return a function with the same signature as createService but will patch the test hooks into the result (we don't know the config type at this point so use reflection).

func GetResponseBodyAndClose

func GetResponseBodyAndClose(b io.ReadCloser) []byte

func GetTestLine

func GetTestLine() string

Types

type Endpoint

type Endpoint interface {
	Expect(tests ...Tests) Endpoint
	ExpectSimple(expectedHeaders map[string]string, expectedBody []byte, returnCode int,
		returnHeaders map[string]string, returnBody []byte, extraTests ...Tests) Endpoint
}

type ResponseTest added in v0.248.0

type ResponseTest func(t syslgo.TestingT, actual *http.Response)

func ExpectResponseHeaders added in v0.248.0

func ExpectResponseHeaders(headers map[string]string, checkForExtra ...bool) ResponseTest

ExpectResponseHeaders: Expects the given headers and their values exist in the response. checkForExtra is an optional parameter to check for extra headers not expected.

func ExpectResponseHeadersDoNotExist added in v0.248.0

func ExpectResponseHeadersDoNotExist(headers []string) ResponseTest

ExpectResponseHeadersDoNotExist: Expects the given header names cannot be found in the response.

func ExpectResponseHeadersExist added in v0.248.0

func ExpectResponseHeadersExist(headers []string) ResponseTest

ExpectResponseHeadersExist: Expects the given header names can be found in the response.

func ExpectResponseHeadersExistExactly added in v0.248.0

func ExpectResponseHeadersExistExactly(headers []string) ResponseTest

ExpectResponseHeadersExistExactly: Expects the given headers in the response exist (and no others).

type TestCall

type TestCall struct {
	Method       string
	URL          string
	Headers      map[string]string
	Body         string
	ExpectedCode int
	ExpectedBody string
	TestCodeFn   func(t syslgo.TestingT, expected, actual int)
	TestBodyFn   func(t syslgo.TestingT, expected, actual string)
}

type TestCall2

type TestCall2 struct {
	Method       string
	URL          string
	Headers      map[string]string
	Body         []byte
	ExpectedCode *int
	ExpectedBody []byte
	TestCodeFn   func(t syslgo.TestingT, actual int)
	TestBodyFn   func(t syslgo.TestingT, actual []byte)
	TestRespFns  []ResponseTest
}

type Tester

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

func NewTester

func NewTester(t syslgo.TestingT, ctx context.Context, yamlConfigData []byte) (*Tester, context.Context, *core.Hooks)

func NewTesterWithBuildMetadata

func NewTesterWithBuildMetadata(t syslgo.TestingT, ctx context.Context, bm status.BuildMetadata, yamlConfigData []byte) (*Tester, context.Context, *core.Hooks)

func (*Tester) BuildID

func (b *Tester) BuildID() string

func (*Tester) BuildMetadata

func (b *Tester) BuildMetadata() *status.BuildMetadata

func (*Tester) CfgBasePath

func (b *Tester) CfgBasePath() string

func (*Tester) Close

func (b *Tester) Close()

func (*Tester) Do

func (b *Tester) Do(tc TestCall)

func (*Tester) Do2

func (b *Tester) Do2(tc TestCall2)

func (*Tester) EndpointURL

func (b *Tester) EndpointURL(suffix string) string

func (*Tester) GetBufDialer added in v0.230.0

func (b *Tester) GetBufDialer(context.Context, string) (net.Conn, error)

func (*Tester) GetName

func (b *Tester) GetName() string

func (*Tester) GracefulStop

func (b *Tester) GracefulStop() error

func (*Tester) HTTPClientGetter

func (b *Tester) HTTPClientGetter(host string) (*http.Client, string, error)

func (*Tester) NewDownstream

func (b *Tester) NewDownstream(host, method, path string) Endpoint

func (*Tester) Start

func (b *Tester) Start() error

func (*Tester) Stop

func (b *Tester) Stop() error

func (*Tester) T added in v0.230.0

func (b *Tester) T() syslgo.TestingT

type Tests

type Tests func(t syslgo.TestingT, w http.ResponseWriter, r *http.Request)

func ExpectBody

func ExpectBody(expected []byte) Tests

func ExpectHeaders

func ExpectHeaders(headers map[string]string, checkForExtra ...bool) Tests

ExpectHeaders: Expects the given headers and their values exist in the response. checkForExtra is an optional parameter to check for extra headers not expected.

func ExpectHeadersDoNotExist

func ExpectHeadersDoNotExist(headers []string) Tests

ExpectHeadersDoNotExist: Expects the given header names cannot be found in the response.

func ExpectHeadersExist

func ExpectHeadersExist(headers []string) Tests

ExpectHeadersExist: Expects the given header names can be found in the response.

func ExpectHeadersExistExactly

func ExpectHeadersExistExactly(headers []string) Tests

ExpectHeadersExistExactly: Expects the given headers in the response exist (and no others).

func ExpectJSONBody

func ExpectJSONBody(expected []byte) Tests

func ExpectQueryParams

func ExpectQueryParams(query map[string][]string) Tests

func ExpectURLParam added in v0.223.0

func ExpectURLParam(key string, expected string) Tests

func ExpectURLParamForInt added in v0.223.0

func ExpectURLParamForInt(key string, expected int64) Tests

func ForceDownstreamTimeout

func ForceDownstreamTimeout() Tests

func Response

func Response(code int, headers map[string]string, body []byte) Tests

Jump to

Keyboard shortcuts

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