Categorygithub.com/yogeshlonkar/aws-lambda-go-test
modulepackage
1.2.0
Repository: https://github.com/yogeshlonkar/aws-lambda-go-test.git
Documentation: pkg.go.dev

# README

aws-lambda-go-test Continuous Integration

A package that allows to run integration test against lambda function locally

Installing

go mod edit -require github.com/yogeshlonkar/aws-lambda-go-test@latest

or

go get -u github.com/yogeshlonkar/aws-lambda-go-test

Example usage

import (
 alt "github.com/yogeshlonkar/aws-lambda-go-test/local"
)

response, err := alt.Run(alt.Input{
    Payload: "payload",
})
if respose != expected {
  // do fail
}

Input parameters

ParametertypeDefault valueDescription
TimeOuttime.Duration5 secondsfor which connection will tried to be made otherwise lambda will be started by this library
Portintrandom if not providedport where lambda is or will be started on
AbsLambdaPathstringmain.go relative to testAbsolute path the lambda go file
Payloadinterface{}-Any structure that can be encoded by the encoding/json package
ClientContext*lc.ClientContext-
Deadline*messages.InvokeRequest_Timestamp-

Run function will set default values and check if the lambda is running or not if not running it will start the lambda and perform RPC API call

Util

util.Response can be used to incrementally test the response returned by lambda. This way the unmarshall is delayed and expected null field un-marshalling can be avoided

import (
  altu "github.com/yogeshlonkar/aws-lambda-go-test/util"
)

response := altu.ParseResponse(responseTxt)

if response.StatusCode != 200 {
  t.Errorf("response.StatusCode=%d, want 200", response.StatusCode)
}

actualHeaders := TestHeaderStruct{} // expected header struct
response.PaseHeaders(&actualHeaders)
if actualHeaders.ContentType == "application/json" {
	t.Errorf("actualHeaders.ContentType=%s, wanted application/json", actualHeaders.ContentType)
}

actualBody := TestBody{} // expected body struct
response.PaseBody(&actualBody)
if len(actualBody.SomeArr) != 1 {
	t.Errorf("len(actualBody.SomeArr)=%d, wanted 1", len(actualBody.SomeArr))
}

Check response_test.go for use of util package

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author