1
1
#[ path = "../src/utils/integration_test_helper.rs" ]
2
2
mod integration_test_helper;
3
3
4
- use hyper :: { Body , Request , Response } ;
4
+ use base :: integration_test ;
5
5
use serial_test:: serial;
6
- use std:: collections:: HashMap ;
7
6
use std:: path:: Path ;
8
- use tokio:: sync:: oneshot;
9
7
use urlencoding:: encode;
10
8
11
- use sb_workers:: context:: { WorkerContextInitOpts , WorkerRequestMsg , WorkerRuntimeOpts } ;
12
-
13
- use crate :: integration_test_helper:: { create_test_user_worker, test_user_runtime_opts} ;
14
-
15
9
#[ tokio:: test]
16
10
#[ serial]
17
11
async fn test_import_map_file_path ( ) {
18
- let opts = WorkerContextInitOpts {
19
- service_path : "./test_cases/with_import_map" . into ( ) ,
20
- no_module_cache : false ,
21
- import_map_path : Some ( "./test_cases/with_import_map/import_map.json" . to_string ( ) ) ,
22
- env_vars : HashMap :: new ( ) ,
23
- events_rx : None ,
24
- timing : None ,
25
- maybe_eszip : None ,
26
- maybe_entrypoint : None ,
27
- maybe_module_code : None ,
28
- conf : WorkerRuntimeOpts :: UserWorker ( test_user_runtime_opts ( ) ) ,
29
- } ;
30
-
31
- let ( worker_req_tx, scope) = create_test_user_worker ( opts) . await . unwrap ( ) ;
32
- let ( res_tx, res_rx) = oneshot:: channel :: < Result < Response < Body > , hyper:: Error > > ( ) ;
33
-
34
- let conn_watch = scope. conn_rx ( ) ;
35
- let req_guard = scope. start_request ( ) . await ;
36
- let req = Request :: builder ( )
37
- . uri ( "/" )
38
- . method ( "GET" )
39
- . body ( Body :: empty ( ) )
40
- . unwrap ( ) ;
41
-
42
- let msg = WorkerRequestMsg {
43
- req,
44
- res_tx,
45
- conn_watch,
46
- } ;
47
-
48
- let _ = worker_req_tx. send ( msg) ;
49
-
50
- let res = res_rx. await . unwrap ( ) . unwrap ( ) ;
51
- assert ! ( res. status( ) . as_u16( ) == 200 ) ;
52
-
53
- let body_bytes = hyper:: body:: to_bytes ( res. into_body ( ) ) . await . unwrap ( ) ;
54
-
55
- assert_eq ! ( body_bytes, r#"{"message":"ok"}"# ) ;
56
- req_guard. await ;
12
+ integration_test ! (
13
+ "./test_cases/with_import_map" ,
14
+ 8989 ,
15
+ "" ,
16
+ None ,
17
+ Some ( "./test_cases/with_import_map/import_map.json" . to_string( ) ) ,
18
+ None :: <reqwest:: RequestBuilder >,
19
+ ( |resp: Result <reqwest:: Response , reqwest:: Error >| async {
20
+ let res = resp. unwrap( ) ;
21
+ assert!( res. status( ) . as_u16( ) == 200 ) ;
22
+
23
+ let body_bytes = res. bytes( ) . await . unwrap( ) ;
24
+ assert_eq!( body_bytes, r#"{"message":"ok"}"# ) ;
25
+ } )
26
+ ) ;
57
27
}
58
28
59
29
#[ tokio:: test]
@@ -76,43 +46,20 @@ async fn test_import_map_inline() {
76
46
. unwrap( )
77
47
)
78
48
) ;
79
- let opts = WorkerContextInitOpts {
80
- service_path : "./test_cases/with_import_map" . into ( ) ,
81
- no_module_cache : false ,
82
- import_map_path : Some ( inline_import_map) ,
83
- env_vars : HashMap :: new ( ) ,
84
- events_rx : None ,
85
- timing : None ,
86
- maybe_eszip : None ,
87
- maybe_entrypoint : None ,
88
- maybe_module_code : None ,
89
- conf : WorkerRuntimeOpts :: UserWorker ( test_user_runtime_opts ( ) ) ,
90
- } ;
91
-
92
- let ( worker_req_tx, scope) = create_test_user_worker ( opts) . await . unwrap ( ) ;
93
- let ( res_tx, res_rx) = oneshot:: channel :: < Result < Response < Body > , hyper:: Error > > ( ) ;
94
-
95
- let conn_watch = scope. conn_rx ( ) ;
96
- let req_guard = scope. start_request ( ) . await ;
97
- let req = Request :: builder ( )
98
- . uri ( "/" )
99
- . method ( "GET" )
100
- . body ( Body :: empty ( ) )
101
- . unwrap ( ) ;
102
-
103
- let msg = WorkerRequestMsg {
104
- req,
105
- res_tx,
106
- conn_watch,
107
- } ;
108
49
109
- let _ = worker_req_tx. send ( msg) ;
110
-
111
- let res = res_rx. await . unwrap ( ) . unwrap ( ) ;
112
- assert ! ( res. status( ) . as_u16( ) == 200 ) ;
113
-
114
- let body_bytes = hyper:: body:: to_bytes ( res. into_body ( ) ) . await . unwrap ( ) ;
115
-
116
- assert_eq ! ( body_bytes, r#"{"message":"ok"}"# ) ;
117
- req_guard. await ;
50
+ integration_test ! (
51
+ "./test_cases/with_import_map" ,
52
+ 8978 ,
53
+ "" ,
54
+ None ,
55
+ Some ( inline_import_map) ,
56
+ None :: <reqwest:: RequestBuilder >,
57
+ ( |resp: Result <reqwest:: Response , reqwest:: Error >| async {
58
+ let res = resp. unwrap( ) ;
59
+ assert!( res. status( ) . as_u16( ) == 200 ) ;
60
+
61
+ let body_bytes = res. bytes( ) . await . unwrap( ) ;
62
+ assert_eq!( body_bytes, r#"{"message":"ok"}"# ) ;
63
+ } )
64
+ ) ;
118
65
}
0 commit comments