Skip to content
Snippets Groups Projects
Commit 4a1a9360 authored by Jano Hendriks's avatar Jano Hendriks
Browse files

Add batch handler to test utils

parent 71843568
Branches
Tags v1.161.0
No related merge requests found
package test_utils
import (
"bytes"
"context"
"fmt"
"github.com/aws/aws-lambda-go/lambda"
......@@ -14,7 +15,7 @@ import (
"os/exec"
)
func StartTestHandler(context context.Context, apiHandler lambda.Handler, sqsHandler lambda.Handler) {
func StartTestHandler(context context.Context, apiHandler lambda.Handler, sqsHandler lambda.Handler, batchFunc func(bodyBytes []byte)) {
if os.Getenv("DEBUG_PROXY") == "true" {
StartProxy()
}
......@@ -27,6 +28,23 @@ func StartTestHandler(context context.Context, apiHandler lambda.Handler, sqsHan
}
}))
http.HandleFunc("/batch/", debugger.Middleware(func(writer http.ResponseWriter, request *http.Request) {
// Read body
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(request.Body)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
request.Body.Close()
batchFunc(buf.Bytes())
}, func(r *http.Request) []string {
return []string{
"path", r.RequestURI,
}
}))
http.HandleFunc("/", debugger.Middleware(func(writer http.ResponseWriter, request *http.Request) {
handler_utils.ServeHTTPFunctions(context, apiHandler, writer, request)
}, func(r *http.Request) []string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment