1
1
mod testcases;
2
2
3
3
mod integration_tests {
4
+ use reqwest:: Method ;
4
5
use sha2:: Digest ;
5
6
use std:: collections:: HashMap ;
6
7
@@ -23,10 +24,7 @@ mod integration_tests {
23
24
let spin = env. runtime_mut ( ) ;
24
25
assert_spin_request (
25
26
spin,
26
- testing_framework:: Request :: new (
27
- reqwest:: Method :: GET ,
28
- & format ! ( "/test?key={test_key}" ) ,
29
- ) ,
27
+ testing_framework:: Request :: new ( Method :: GET , & format ! ( "/test?key={test_key}" ) ) ,
30
28
testing_framework:: Response :: new_with_body ( 200 , test_value) ,
31
29
)
32
30
} ,
@@ -46,28 +44,25 @@ mod integration_tests {
46
44
let spin = env. runtime_mut ( ) ;
47
45
assert_spin_request (
48
46
spin,
49
- testing_framework:: Request :: new ( reqwest :: Method :: GET , "/test/hello" ) ,
47
+ testing_framework:: Request :: new ( Method :: GET , "/test/hello" ) ,
50
48
testing_framework:: Response :: new_with_body ( 200 , "I'm a teapot" ) ,
51
49
) ?;
52
50
assert_spin_request (
53
51
spin,
54
52
testing_framework:: Request :: new (
55
- reqwest :: Method :: GET ,
53
+ Method :: GET ,
56
54
"/test/hello/wildcards/should/be/handled" ,
57
55
) ,
58
56
testing_framework:: Response :: new_with_body ( 200 , "I'm a teapot" ) ,
59
57
) ?;
60
58
assert_spin_request (
61
59
spin,
62
- testing_framework:: Request :: new ( reqwest :: Method :: GET , "/thishsouldfail" ) ,
60
+ testing_framework:: Request :: new ( Method :: GET , "/thishsouldfail" ) ,
63
61
testing_framework:: Response :: new ( 404 ) ,
64
62
) ?;
65
63
assert_spin_request (
66
64
spin,
67
- testing_framework:: Request :: new (
68
- reqwest:: Method :: GET ,
69
- "/test/hello/test-placement" ,
70
- ) ,
65
+ testing_framework:: Request :: new ( Method :: GET , "/test/hello/test-placement" ) ,
71
66
testing_framework:: Response :: new_with_body ( 200 , "text for test" ) ,
72
67
)
73
68
} ,
@@ -152,7 +147,7 @@ mod integration_tests {
152
147
let spin = env. runtime_mut ( ) ;
153
148
assert_spin_request (
154
149
spin,
155
- testing_framework:: Request :: new ( reqwest :: Method :: GET , "/env" ) ,
150
+ testing_framework:: Request :: new ( Method :: GET , "/env" ) ,
156
151
testing_framework:: Response :: full (
157
152
200 ,
158
153
[
@@ -185,7 +180,7 @@ mod integration_tests {
185
180
assert_spin_request (
186
181
spin,
187
182
testing_framework:: Request :: new (
188
- reqwest :: Method :: GET ,
183
+ Method :: GET ,
189
184
& format ! ( "/static/thisshouldbemounted/{name}" ) ,
190
185
) ,
191
186
testing_framework:: Response :: new_with_body ( 200 , content) ,
@@ -203,10 +198,7 @@ mod integration_tests {
203
198
let mut assert_not_found = |path : & str | {
204
199
assert_spin_request (
205
200
spin,
206
- testing_framework:: Request :: new (
207
- reqwest:: Method :: GET ,
208
- & format ! ( "/static/{path}" ) ,
209
- ) ,
201
+ testing_framework:: Request :: new ( Method :: GET , & format ! ( "/static/{path}" ) ) ,
210
202
testing_framework:: Response :: new_with_body ( 404 , "Not Found" ) ,
211
203
)
212
204
} ;
@@ -233,7 +225,7 @@ mod integration_tests {
233
225
let mut test = |lang : & str , body : & str | {
234
226
assert_spin_request (
235
227
spin,
236
- testing_framework:: Request :: new ( reqwest :: Method :: GET , & format ! ( "/{lang}" ) ) ,
228
+ testing_framework:: Request :: new ( Method :: GET , & format ! ( "/{lang}" ) ) ,
237
229
testing_framework:: Response :: new_with_body ( 200 , body) ,
238
230
)
239
231
} ;
@@ -279,16 +271,13 @@ Caused by:
279
271
let spin = env. runtime_mut ( ) ;
280
272
assert_spin_request (
281
273
spin,
282
- testing_framework:: Request :: new ( reqwest :: Method :: GET , "/test/outbound-allowed" ) ,
274
+ testing_framework:: Request :: new ( Method :: GET , "/test/outbound-allowed" ) ,
283
275
testing_framework:: Response :: new_with_body ( 200 , "Hello, Fermyon!\n " ) ,
284
276
) ?;
285
277
286
278
assert_spin_request (
287
279
spin,
288
- testing_framework:: Request :: new (
289
- reqwest:: Method :: GET ,
290
- "/test/outbound-not-allowed" ,
291
- ) ,
280
+ testing_framework:: Request :: new ( Method :: GET , "/test/outbound-not-allowed" ) ,
292
281
testing_framework:: Response :: new ( 500 ) ,
293
282
) ?;
294
283
@@ -314,7 +303,7 @@ Caused by:
314
303
|env| {
315
304
let spin = env. runtime_mut ( ) ;
316
305
let mut ensure_success = |uri, expected_status, expected_body| {
317
- let request = testing_framework:: Request :: new ( reqwest :: Method :: GET , uri) ;
306
+ let request = testing_framework:: Request :: new ( Method :: GET , uri) ;
318
307
assert_spin_request (
319
308
spin,
320
309
request,
@@ -346,7 +335,7 @@ Caused by:
346
335
|env| {
347
336
let spin = env. runtime_mut ( ) ;
348
337
let mut ensure_success = |uri, expected_status, expected_body| {
349
- let request = testing_framework:: Request :: new ( reqwest :: Method :: GET , uri) ;
338
+ let request = testing_framework:: Request :: new ( Method :: GET , uri) ;
350
339
assert_spin_request (
351
340
spin,
352
341
request,
@@ -397,7 +386,7 @@ Caused by:
397
386
. status ( ) ;
398
387
assert_eq ! ( status, 200 ) ;
399
388
let spin = env. runtime_mut ( ) ;
400
- let request = testing_framework:: Request :: new ( reqwest :: Method :: GET , "/" ) ;
389
+ let request = testing_framework:: Request :: new ( Method :: GET , "/" ) ;
401
390
assert_spin_request (
402
391
spin,
403
392
request,
@@ -596,7 +585,7 @@ Caused by:
596
585
) ?;
597
586
assert_spin_request (
598
587
env. runtime_mut ( ) ,
599
- testing_framework:: Request :: new ( reqwest :: Method :: GET , "/" ) ,
588
+ testing_framework:: Request :: new ( Method :: GET , "/" ) ,
600
589
testing_framework:: Response :: new_with_body ( 200 , "Hello, Fermyon" ) ,
601
590
) ?;
602
591
Ok ( ( ) )
@@ -627,7 +616,7 @@ Caused by:
627
616
assert_spin_request (
628
617
env. runtime_mut ( ) ,
629
618
testing_framework:: Request :: full (
630
- reqwest :: Method :: GET ,
619
+ Method :: GET ,
631
620
"/" ,
632
621
& [ ( "url" , & format ! ( "http://127.0.0.1:{port}/" , ) ) ] ,
633
622
Some ( body. as_bytes ( ) ) ,
@@ -936,12 +925,8 @@ route = "/..."
936
925
headers. push ( ( "url" , & url) ) ;
937
926
}
938
927
let uri = format ! ( "/{uri}" ) ;
939
- let request = testing_framework:: Request :: full (
940
- reqwest:: Method :: POST ,
941
- & uri,
942
- & headers,
943
- Some ( body) ,
944
- ) ;
928
+ let request =
929
+ testing_framework:: Request :: full ( Method :: POST , & uri, & headers, Some ( body) ) ;
945
930
assert_spin_request (
946
931
spin,
947
932
request,
@@ -1008,7 +993,7 @@ route = "/..."
1008
993
. map ( |( k, v) | ( * k, v. as_str ( ) ) )
1009
994
. collect :: < Vec < _ > > ( ) ;
1010
995
let request = testing_framework:: Request :: full (
1011
- reqwest :: Method :: GET ,
996
+ Method :: GET ,
1012
997
"/hash-all" ,
1013
998
& headers,
1014
999
Option :: < Vec < u8 > > :: None ,
@@ -1047,23 +1032,53 @@ route = "/..."
1047
1032
}
1048
1033
1049
1034
#[ test]
1050
- fn test_wagi_http ( ) -> anyhow:: Result < ( ) > {
1035
+ fn test_spin_inbound_http ( ) -> anyhow:: Result < ( ) > {
1051
1036
run_test (
1052
- "wagi -http" ,
1037
+ "spin-inbound -http" ,
1053
1038
testing_framework:: SpinMode :: Http ,
1054
1039
[ ] ,
1055
1040
testing_framework:: ServicesConfig :: none ( ) ,
1056
1041
move |env| {
1057
1042
let spin = env. runtime_mut ( ) ;
1058
1043
assert_spin_request (
1059
1044
spin,
1060
- testing_framework:: Request :: new ( reqwest:: Method :: GET , "/base/hello" ) ,
1061
- testing_framework:: Response :: new_with_body ( 200 , "I'm a teapot" ) ,
1045
+ testing_framework:: Request :: full (
1046
+ Method :: GET ,
1047
+ "/base/echo" ,
1048
+ & [ ] ,
1049
+ Some ( "Echo..." ) ,
1050
+ ) ,
1051
+ testing_framework:: Response :: new_with_body ( 200 , "Echo..." ) ,
1062
1052
) ?;
1063
1053
assert_spin_request (
1064
1054
spin,
1065
1055
testing_framework:: Request :: full (
1066
- reqwest:: Method :: GET ,
1056
+ Method :: GET ,
1057
+ "/base/assert-headers?k=v" ,
1058
+ & [ ( "X-Custom-Foo" , "bar" ) ] ,
1059
+ Some ( r#"{"x-custom-foo": "bar"}"# ) ,
1060
+ ) ,
1061
+ testing_framework:: Response :: new ( 200 ) ,
1062
+ ) ?;
1063
+ Ok ( ( ) )
1064
+ } ,
1065
+ ) ?;
1066
+ Ok ( ( ) )
1067
+ }
1068
+
1069
+ #[ test]
1070
+ fn test_wagi_http ( ) -> anyhow:: Result < ( ) > {
1071
+ run_test (
1072
+ "wagi-http" ,
1073
+ testing_framework:: SpinMode :: Http ,
1074
+ [ ] ,
1075
+ testing_framework:: ServicesConfig :: none ( ) ,
1076
+ move |env| {
1077
+ let spin = env. runtime_mut ( ) ;
1078
+ assert_spin_request (
1079
+ spin,
1080
+ testing_framework:: Request :: full (
1081
+ Method :: GET ,
1067
1082
"/base/echo" ,
1068
1083
& [ ] ,
1069
1084
Some ( "Echo..." ) ,
@@ -1072,19 +1087,25 @@ route = "/..."
1072
1087
) ?;
1073
1088
assert_spin_request (
1074
1089
spin,
1075
- testing_framework:: Request :: new ( reqwest:: Method :: GET , "/base/args?x=y" ) ,
1076
- testing_framework:: Response :: new_with_body ( 200 , r#"["/base/args", "x=y"]"# ) ,
1090
+ testing_framework:: Request :: full (
1091
+ Method :: GET ,
1092
+ "/base/assert-args?x=y" ,
1093
+ & [ ] ,
1094
+ Some ( r#"["/base/assert-args", "x=y"]"# ) ,
1095
+ ) ,
1096
+ testing_framework:: Response :: new ( 200 ) ,
1077
1097
) ?;
1078
1098
assert_spin_request (
1079
1099
spin,
1080
1100
testing_framework:: Request :: full (
1081
- reqwest :: Method :: GET ,
1082
- "/base/env?HTTP_X_CUSTOM_FOO " ,
1101
+ Method :: GET ,
1102
+ "/base/assert- env" ,
1083
1103
& [ ( "X-Custom-Foo" , "bar" ) ] ,
1084
- Option :: < Vec < u8 > > :: None ,
1104
+ Some ( r#"{"HTTP_X_CUSTOM_FOO": "bar"}"# ) ,
1085
1105
) ,
1086
- testing_framework:: Response :: new_with_body ( 200 , "bar" ) ,
1087
- )
1106
+ testing_framework:: Response :: new ( 200 ) ,
1107
+ ) ?;
1108
+ Ok ( ( ) )
1088
1109
} ,
1089
1110
) ?;
1090
1111
@@ -1106,7 +1127,7 @@ route = "/..."
1106
1127
) ;
1107
1128
let headers = [ ( "url" , service_url. as_str ( ) ) ] ;
1108
1129
let request: testing_framework:: Request < ' _ , Vec < u8 > > =
1109
- testing_framework:: Request :: full ( reqwest :: Method :: GET , "/" , & headers, None ) ;
1130
+ testing_framework:: Request :: full ( Method :: GET , "/" , & headers, None ) ;
1110
1131
let expected = testing_framework:: Response :: new_with_body ( 200 , "Hello, world!" ) ;
1111
1132
assert_spin_request ( env. runtime_mut ( ) , request, expected)
1112
1133
} ,
0 commit comments