Documentation ¶
Index ¶
- Constants
- type GivenWrapper
- func (g *GivenWrapper) Body(body interface{}) *GivenWrapper
- func (g *GivenWrapper) Context(name string, value interface{}) *GivenWrapper
- func (g *GivenWrapper) Method(method string) *GivenWrapper
- func (g *GivenWrapper) Module(module xapi.Module) *GivenWrapper
- func (g *GivenWrapper) Path(path string, args ...interface{}) *GivenWrapper
- type TestManager
- func (m *TestManager) Given() *GivenWrapper
- func (m *TestManager) Json(jsonStr string) interface{}
- func (m *TestManager) JsonFile(fileName string) interface{}
- func (m *TestManager) Then() *ThenWrapper
- func (m *TestManager) When() *WhenWrapper
- func (m *TestManager) WithDefaultErrorHandler(useDefault ...bool) *TestManager
- func (m *TestManager) WithErrorHandler(errorHandler echo.HTTPErrorHandler) *TestManager
- func (m *TestManager) WithServer(server *echo.Echo) *TestManager
- type ThenWrapper
- func (t *ThenWrapper) BodyFieldHasValue(jsonPath string) *ThenWrapper
- func (t *ThenWrapper) BodyFieldIs(jsonPath string, expectedValue interface{}) *ThenWrapper
- func (t *ThenWrapper) BodyFieldSatisfies(jsonPath string, predicate func(*testing.T, interface{})) *ThenWrapper
- func (t *ThenWrapper) BodyIs(expectedBody interface{}) *ThenWrapper
- func (t *ThenWrapper) ContentTypeIs(expectedType string) *ThenWrapper
- func (t *ThenWrapper) ContentTypeIsJson() *ThenWrapper
- func (t *ThenWrapper) GetContextAfterCall() echo.Context
- func (t *ThenWrapper) StatusCodeIs(expectedStatusCode int) *ThenWrapper
- type WhenWrapper
Constants ¶
const HeaderContentType = "Content-Type"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GivenWrapper ¶
type GivenWrapper struct {
// contains filtered or unexported fields
}
func (*GivenWrapper) Body ¶
func (g *GivenWrapper) Body(body interface{}) *GivenWrapper
Body sets the body to use when calling the handler
func (*GivenWrapper) Context ¶
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 ¶
func (g *GivenWrapper) Method(method string) *GivenWrapper
Method sets the method to use
func (*GivenWrapper) Module ¶
func (g *GivenWrapper) Module(module xapi.Module) *GivenWrapper
func (*GivenWrapper) Path ¶
func (g *GivenWrapper) Path(path string, args ...interface{}) *GivenWrapper
Path sets the path called
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 ¶
type ThenWrapper struct {
// contains filtered or unexported fields
}
func (*ThenWrapper) BodyFieldHasValue ¶
func (t *ThenWrapper) BodyFieldHasValue(jsonPath string) *ThenWrapper
func (*ThenWrapper) BodyFieldIs ¶
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 ¶
func (t *ThenWrapper) BodyFieldSatisfies(jsonPath string, predicate func(*testing.T, interface{})) *ThenWrapper
func (*ThenWrapper) BodyIs ¶
func (t *ThenWrapper) BodyIs(expectedBody interface{}) *ThenWrapper
BodyIs verifies the response body has the expected value
func (*ThenWrapper) ContentTypeIs ¶
func (t *ThenWrapper) ContentTypeIs(expectedType string) *ThenWrapper
ContentTypeIs verifies the response has the expected content type
func (*ThenWrapper) ContentTypeIsJson ¶
func (t *ThenWrapper) ContentTypeIsJson() *ThenWrapper
ContentTypeIsJson verifies the response has the expected JSON content type
func (*ThenWrapper) GetContextAfterCall ¶
func (t *ThenWrapper) GetContextAfterCall() echo.Context
func (*ThenWrapper) StatusCodeIs ¶
func (t *ThenWrapper) StatusCodeIs(expectedStatusCode int) *ThenWrapper
StatusCodeIs verifies the response has the expected status code
type WhenWrapper ¶
type WhenWrapper struct {
// contains filtered or unexported fields
}
func (*WhenWrapper) CallsPath ¶
func (w *WhenWrapper) CallsPath(pathFmt string, args ...any) *WhenWrapper
func (*WhenWrapper) PerformTheCall ¶
func (w *WhenWrapper) PerformTheCall() *WhenWrapper
PerformTheCall Deprecated, use Module() and CallsPath() instead