Chapter 10: Testing Your Serverless Application

  1. Write a unit test for the UpdateMovie Lambda function. Answer:
package mainimport (  "testing"  "github.com/stretchr/testify/assert"  "github.com/aws/aws-lambda-go/events")func TestUpdate_InvalidPayLoad(t *testing.T) {  input := events.APIGatewayProxyRequest{    Body: "{'name': 'avengers'}",  }  expected := events.APIGatewayProxyResponse{    StatusCode: 400,    Body: "Invalid payload",  }  response, _ := update(input)  assert.Equal(t, expected, response)}func TestUpdate_ValidPayload(t *testing.T) {  input := events.APIGatewayProxyRequest{    Body: "{\"id\":\"40\", \"name\":\"Thor\", \"description\":\"Marvel movie\", \"cover\":\"poster url\"}",  }  expected := events.APIGatewayProxyResponse{ Body: "{\"id\":\"40\", ...

Get Hands-On Serverless Applications with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.