-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathruntime_test.ml
81 lines (76 loc) · 2.36 KB
/
runtime_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
open Test_common
module Runtime = struct
include
Lambda_runtime__.Runtime.Make
(Lambda_runtime__.Json.Id)
(Lambda_runtime__.Json.Id)
type event = Lambda_runtime__.Json.Id.t
type response = Lambda_runtime__.Json.Id.t
end
let request = `String "test"
let test_runtime = test_runtime_generic (module Runtime) request
exception User_code_exception
let suite =
[ ( "successful handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Ok (`String "Hello"))
(fun output ->
match output with
| Ok result ->
Alcotest.check
yojson
"runtime invoke output"
(`String "Hello")
result
| Error e -> Alcotest.fail e) )
; ( "failed handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> Error "I failed")
(fun output ->
match output with
| Ok result ->
let result_str = Yojson.Safe.to_string result 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 (`String "Hello"))
(fun output ->
match output with
| Ok result ->
Alcotest.check
yojson
"runtime invoke output"
(`String "Hello")
result
| Error e -> Alcotest.fail e) )
; ( "failed handler invocation"
, `Quick
, test_runtime
(fun _event _ctx -> raise User_code_exception)
(fun output ->
match output with
| Ok result ->
let result_str = Yojson.Safe.to_string result in
Alcotest.fail
(Printf.sprintf
"Expected to get an error but the call succeeded with: %s"
result_str)
| Error e ->
let expected =
"Handler raised: Dune__exe__Runtime_test.User_code_exception\n"
in
Alcotest.(
check
string
"Runtime invoke error"
expected
(String.sub e 0 (String.length expected)))) )
]