-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapi_gateway_test.ml
90 lines (81 loc) · 2.47 KB
/
api_gateway_test.ml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
open Test_common
module Http = Lambda_runtime__.Http
module StringMap = Map.Make (String)
let apigw_response =
(module struct
type t = Http.api_gateway_proxy_response
let pp formatter t =
Format.pp_print_text
formatter
(t
|> Http.API_gateway_response.to_yojson
|> Yojson.Safe.pretty_to_string)
let equal = ( = )
end : Alcotest.TESTABLE
with type t = Http.api_gateway_proxy_response)
module Http_runtime = struct
include Http
type event = Http.API_gateway_request.t
type response = Http.API_gateway_response.t
end
let request =
Test_common.make_test_request (module Http.API_gateway_request) "apigw_real"
let test_fixture = Test_common.test_fixture (module Http.API_gateway_request)
let test_runtime = test_runtime_generic (module Http_runtime) request
let response =
Http.
{ status_code = 200
; headers = StringMap.empty
; body = "Hello"
; is_base64_encoded = false
}
let suite =
[ "deserialize (mock) API Gateway Proxy Request", `Quick, test_fixture "apigw"
; ( "deserialize (real world) API Gateway Proxy Request"
, `Quick
, test_fixture "apigw_real_trimmed" )
; ( "successful handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Ok response)
(fun output ->
match output with
| Ok result ->
Alcotest.check
apigw_response
"runtime invoke output"
response
result
| Error e -> Alcotest.fail e) )
; ( "failed handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Error "I failed")
(fun output ->
match output with
| Ok response ->
let result_str =
response
|> Http.API_gateway_response.to_yojson
|> Yojson.Safe.pretty_to_string
in
Alcotest.fail
(Printf.sprintf
"Expected to get an error but the call succeeded with: %s"
result_str)
| Error e ->
Alcotest.(check string "Runtime invoke error" "I failed" e)) )
; ( "simple asynchronous handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Ok response)
(fun output ->
match output with
| Ok result ->
Alcotest.check
apigw_response
"runtime invoke output"
response
result
| Error e -> Alcotest.fail e) )
]