-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvercel_test.ml
90 lines (81 loc) · 2.54 KB
/
vercel_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 Vercel = Vercel__
let vercel_lambda_response =
(module struct
open Vercel
type t = Response.t
let pp formatter t =
Format.pp_print_text
formatter
(t |> Response.to_yojson |> Yojson.Safe.pretty_to_string)
let equal = ( = )
end : Alcotest.TESTABLE
with type t = Vercel.Response.t)
module Runtime = struct
include Lambda_runtime__.Runtime.Make (Vercel.Request) (Vercel.Response)
type event = Vercel.Request.t
type response = Vercel.Response.t
end
let request =
Test_common.make_test_request (module Vercel.Request) "now_with_body"
let test_fixture = Test_common.test_fixture (module Vercel.Request)
let test_runtime = test_runtime_generic (module Runtime) request
let response = Piaf.Response.of_string `OK ~body:""
let suite =
[ ( "deserialize Vercel Proxy Request without HTTP Body"
, `Quick
, test_fixture "now_no_body" )
; ( "deserialize Vercel Proxy Request with HTTP Body"
, `Quick
, test_fixture "now_with_body" )
; ( "deserialize Vercel Proxy Request 2/2023"
, `Quick
, test_fixture "vercel-request" )
; ( "deserialize Vercel Proxy Request 2/2023 / 2"
, `Quick
, test_fixture "vercel-request-2" )
; ( "successful handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Ok response)
(fun output ->
match output with
| Ok result ->
Alcotest.check
vercel_lambda_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
|> Vercel.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
vercel_lambda_response
"runtime invoke output"
response
result
| Error e -> Alcotest.fail e) )
]