restest

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 14 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const HeaderContentType = "Content-Type"

Variables

This section is empty.

Functions

This section is empty.

Types

type GivenWrapper added in v0.28.0

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

func (*GivenWrapper) Body added in v0.28.0

func (g *GivenWrapper) Body(body interface{}) *GivenWrapper

Body sets the body to use when calling the handler

func (*GivenWrapper) Context added in v0.28.0

func (g *GivenWrapper) Context(name string, value interface{}) *GivenWrapper

Context sets a value in the request context under the given name. Used to store current user, current request id, etc.

func (*GivenWrapper) Method added in v0.28.0

func (g *GivenWrapper) Method(method string) *GivenWrapper

Method sets the method to use

func (*GivenWrapper) Module added in v0.28.0

func (g *GivenWrapper) Module(module xapi.Module) *GivenWrapper

func (*GivenWrapper) Path added in v0.28.0

func (g *GivenWrapper) Path(path string, args ...interface{}) *GivenWrapper

Path sets the path called

func (*GivenWrapper) PathParam added in v0.28.0

func (g *GivenWrapper) PathParam(name string, value string) *GivenWrapper

PathParam sets a value in the request context under the given name. Used to store entity id, etc. Deprecated, use Module() and CallsPath() instead

type TestManager

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

TestManager is helper to test REST handler created with echo HTTP server

func For

func For(t *testing.T) *TestManager

For builds a test manager using the provided test context T

func (*TestManager) Given

func (m *TestManager) Given() *GivenWrapper

Given returns the GIVEN builder. It allows to define the preconditions for the test

func (*TestManager) Json

func (m *TestManager) Json(jsonStr string) interface{}

Json allows to define the request or response body from JSON in a string.

func (*TestManager) JsonFile

func (m *TestManager) JsonFile(fileName string) interface{}

JsonFile allows to define the request or response body from JSON in a string.

func (*TestManager) Then

func (m *TestManager) Then() *ThenWrapper

Then returns the THEN builder. It allows to verify the expectations (post conditions) for the test

func (*TestManager) When

func (m *TestManager) When() *WhenWrapper

When returns the WHEN builder. It allows to execute the handler under test

func (*TestManager) WithDefaultErrorHandler

func (m *TestManager) WithDefaultErrorHandler(useDefault ...bool) *TestManager

WithDefaultErrorHandler adds to the TestManager the default error handler to convert errors to HTTP codes This is the default behavior. TO remove the default error handler, use WithErrorHandler(false)

func (*TestManager) WithErrorHandler

func (m *TestManager) WithErrorHandler(errorHandler echo.HTTPErrorHandler) *TestManager

WithErrorHandler adds to the TestManager an error handler to convert errors to HTTP codes

func (*TestManager) WithServer

func (m *TestManager) WithServer(server *echo.Echo) *TestManager

type ThenWrapper added in v0.28.0

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

func (*ThenWrapper) BodyFieldHasValue added in v0.28.0

func (t *ThenWrapper) BodyFieldHasValue(jsonPath string) *ThenWrapper

func (*ThenWrapper) BodyFieldIs added in v0.28.0

func (t *ThenWrapper) BodyFieldIs(jsonPath string, expectedValue interface{}) *ThenWrapper

BodyFieldIs verifies the response body contains a filed in the provided path with the expected value.

The path is given in JSONPath format. See https://goessner.net/articles/JsonPath/

func (*ThenWrapper) BodyFieldSatisfies added in v0.28.0

func (t *ThenWrapper) BodyFieldSatisfies(jsonPath string, predicate func(*testing.T, interface{})) *ThenWrapper

func (*ThenWrapper) BodyIs added in v0.28.0

func (t *ThenWrapper) BodyIs(expectedBody interface{}) *ThenWrapper

BodyIs verifies the response body has the expected value

func (*ThenWrapper) ContentTypeIs added in v0.28.0

func (t *ThenWrapper) ContentTypeIs(expectedType string) *ThenWrapper

ContentTypeIs verifies the response has the expected content type

func (*ThenWrapper) ContentTypeIsJson added in v0.28.0

func (t *ThenWrapper) ContentTypeIsJson() *ThenWrapper

ContentTypeIsJson verifies the response has the expected JSON content type

func (*ThenWrapper) GetContextAfterCall added in v0.28.0

func (t *ThenWrapper) GetContextAfterCall() echo.Context

func (*ThenWrapper) StatusCodeIs added in v0.28.0

func (t *ThenWrapper) StatusCodeIs(expectedStatusCode int) *ThenWrapper

StatusCodeIs verifies the response has the expected status code

type WhenWrapper added in v0.28.0

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

func (*WhenWrapper) Calls added in v0.28.0

func (w *WhenWrapper) Calls(handler func(c echo.Context) error) *WhenWrapper

Calls execute the request to the handler. A proper initialized echo.Context is build and used as parameter Deprecated, use Module() and CallsPath() instead

func (*WhenWrapper) CallsPath added in v0.28.0

func (w *WhenWrapper) CallsPath(pathFmt string, args ...any) *WhenWrapper

func (*WhenWrapper) PerformTheCall added in v0.28.0

func (w *WhenWrapper) PerformTheCall() *WhenWrapper

PerformTheCall Deprecated, use Module() and CallsPath() instead

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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