-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgolamb_test.go
68 lines (62 loc) · 1.6 KB
/
golamb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package golamb
import (
"context"
"encoding/json"
"errors"
"net/http"
"reflect"
"testing"
"github.com/aws/aws-lambda-go/events"
)
func TestGetHandler(t *testing.T) {
f := func(c Context) Responder {
return c.Response(http.StatusOK)
}
h := getHandler(f)
payload, err := json.Marshal(&events.APIGatewayV2HTTPRequest{})
if err != nil {
t.Fatalf("unexpected err: %s", err)
}
resp, err := h.Invoke(context.Background(), payload)
if err != nil {
t.Fatalf("unexpected err: %s", err)
}
var got events.APIGatewayV2HTTPResponse
if err := json.Unmarshal(resp, &got); err != nil {
t.Fatalf("unexpected err: %s", err)
}
want := events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
}
}
func TestGetConfigEmpty(t *testing.T) {
if getConfig().PanicHandler == nil {
t.Fatalf("unexpected nil panic handler")
}
}
func TestGetConfigProvided(t *testing.T) {
want := &Config{
PanicHandler: defaultPanicHandler,
}
got := getConfig(want)
if got.PanicHandler == nil {
t.Fatalf("unexpected nil panic handler")
}
}
func TestPanicHandler(t *testing.T) {
got, err := defaultPanicHandler(&handlerContext{logger: NewDefaultLogger()}, errors.New("foo")).Respond()
if err != nil {
t.Fatalf("unexpected err: %s", err)
}
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusInternalServerError,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
}
}