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
No related branches found
No related tags found
No related merge requests found
package test_utils package test_utils
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"github.com/aws/aws-lambda-go/lambda" "github.com/aws/aws-lambda-go/lambda"
...@@ -14,7 +15,7 @@ import ( ...@@ -14,7 +15,7 @@ import (
"os/exec" "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" { if os.Getenv("DEBUG_PROXY") == "true" {
StartProxy() StartProxy()
} }
...@@ -27,6 +28,23 @@ func StartTestHandler(context context.Context, apiHandler lambda.Handler, sqsHan ...@@ -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) { http.HandleFunc("/", debugger.Middleware(func(writer http.ResponseWriter, request *http.Request) {
handler_utils.ServeHTTPFunctions(context, apiHandler, writer, request) handler_utils.ServeHTTPFunctions(context, apiHandler, writer, request)
}, func(r *http.Request) []string { }, 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