tagol

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 3 Imported by: 0

README

tagol

TAGOL (Test A GO Lambda) is a small DSL to test an AWS API Gateway-proxified AWS Lambda implemented in Go.

Usage

See the generated Go doc. Below, a short example :

    // main.go
	func handleRequest(request events.APIGatewayProxyRequest) (response events.APIGatewayProxyResponse, err error) {
		return
	}

    // main_test.go
    func TestHttpOk(t *testing.T) {
        tagol.Invoking(handleRequest).
            Should(t).
            ReturnNoError().
            ReturnStatus(http.StatusOK)
    }

License

Provided under the MIT License.

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

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

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

Jump to

Keyboard shortcuts

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