Documentation ¶
Overview ¶
Package tagol (Test A GO Lambda) implements an AWS API Gateway-invoked Lambda function testing library. Tagol allows you to use a fluent, DSL-like interface to test your HTTP-handling AWS Lambda (using API Gateway proxy integration).
Example ¶
tester := new(mockedFatalfer) fut := func(request events.APIGatewayProxyRequest) (response events.APIGatewayProxyResponse, err error) { raw, err := json.Marshal(testingType{Name: "legend", Area: 110}) response.Body = string(raw) response.Headers = map[string]string{"Gopher-Name": "Goophy"} response.StatusCode = http.StatusOK return } // Act Invoking(fut). WithPathParameter("id", "a110"). WithQuery("area", "gt42"). WithHeader("Warning", "High speed cars ahead"). WithBody(testingType{Name: "A", Area: 32}). // Assert Should(tester). ReturnNoError(). ReturnHeader("Gopher-Name", "Goophy"). ReturnValidatedBodyAs(new(testingType), func(_ interface{}) error { return nil }). ReturnStatus(http.StatusOK) fmt.Printf("Tests passed : %v", !tester.fail)
Output: Tests passed : true
Index ¶
- type Assertions
- func (a Assertions) ReturnBodyAs(actual, expected interface{}) Assertions
- func (a Assertions) ReturnError(expected string)
- func (a Assertions) ReturnHeader(key, expected string) Assertions
- func (a Assertions) ReturnNoError() Assertions
- func (a Assertions) ReturnStatus(expected int) Assertions
- func (a Assertions) ReturnValidatedBodyAs(actual interface{}, validator func(interface{}) error) Assertions
- type Invocation
- func (i Invocation) Should(fatalfer fatalfer) Assertions
- func (i Invocation) WithBody(body interface{}) Invocation
- func (i Invocation) WithHeader(key, value string) Invocation
- func (i Invocation) WithMethod(method string) Invocation
- func (i Invocation) WithPathParameter(key, value string) Invocation
- func (i Invocation) WithQuery(key, value string) Invocation
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assertions ¶ added in v0.1.3
type Assertions struct {
// contains filtered or unexported fields
}
Assertions allows you to make assertions on the function's response and fails the test if an assertion is not met
func (Assertions) ReturnBodyAs ¶ added in v0.1.3
func (a Assertions) ReturnBodyAs(actual, expected interface{}) Assertions
ReturnBodyAs fails if the function did not returned a JSON body that can be unmarshaled to the first (must be pointer) argument or if it's not equal to the second (must be pointer) argument
func (Assertions) ReturnError ¶ added in v0.1.3
func (a Assertions) ReturnError(expected string)
ReturnError fails if the function did not returned an error that matches the provided string
func (Assertions) ReturnHeader ¶ added in v0.1.3
func (a Assertions) ReturnHeader(key, expected string) Assertions
ReturnHeader fails if the function did not set the specified header
func (Assertions) ReturnNoError ¶ added in v0.1.3
func (a Assertions) ReturnNoError() Assertions
ReturnNoError fails if the function returned an error
func (Assertions) ReturnStatus ¶ added in v0.1.3
func (a Assertions) ReturnStatus(expected int) Assertions
ReturnStatus fails if the function did not returned the expected HTTP status code
func (Assertions) ReturnValidatedBodyAs ¶ added in v0.1.3
func (a Assertions) ReturnValidatedBodyAs(actual interface{}, validator func(interface{}) error) Assertions
ReturnValidatedBodyAs fails if the function did not returned a JSON body that can be unmarshaled to the first (must be pointer) argument or if the provided validation function returns a non-nil error when called with the unmarshaled argument
type Invocation ¶ added in v0.1.3
type Invocation struct {
// contains filtered or unexported fields
}
Invocation represents a call to the tested Lambda along with the testing request parameters
func Invoking ¶
func Invoking(function func(events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)) Invocation
Invoking returns an Invocation from the provided API Gateway-proxified Lambda function
func (Invocation) Should ¶ added in v0.1.3
func (i Invocation) Should(fatalfer fatalfer) Assertions
Should takes a *testing.T or any value that provides a Fatalf(string, ...interface{}) method and returns an Assertions
func (Invocation) WithBody ¶ added in v0.1.3
func (i Invocation) WithBody(body interface{}) Invocation
WithBody sets the invocation's request body by marshalling the provided interface{} to JSON
func (Invocation) WithHeader ¶ added in v0.1.3
func (i Invocation) WithHeader(key, value string) Invocation
WithHeader adds a header to the invocation's request parameters
func (Invocation) WithMethod ¶ added in v0.1.3
func (i Invocation) WithMethod(method string) Invocation
WithMethod sets the invocation's method
func (Invocation) WithPathParameter ¶ added in v0.1.3
func (i Invocation) WithPathParameter(key, value string) Invocation
WithPathParameter adds a path parameter to the invocation's request parameters
func (Invocation) WithQuery ¶ added in v0.1.3
func (i Invocation) WithQuery(key, value string) Invocation
WithQuery adds a query parameter to the invocation's request parameters