Skip to content

Commit 6445f70

Browse files
committed
integration tests: use reqwest::Method
Signed-off-by: Lann Martin <[email protected]>
1 parent 3655b68 commit 6445f70

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

tests/integration.rs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod testcases;
22

33
mod integration_tests {
4+
use reqwest::Method;
45
use sha2::Digest;
56
use std::collections::HashMap;
67

@@ -23,10 +24,7 @@ mod integration_tests {
2324
let spin = env.runtime_mut();
2425
assert_spin_request(
2526
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}")),
3028
testing_framework::Response::new_with_body(200, test_value),
3129
)
3230
},
@@ -46,28 +44,25 @@ mod integration_tests {
4644
let spin = env.runtime_mut();
4745
assert_spin_request(
4846
spin,
49-
testing_framework::Request::new(reqwest::Method::GET, "/test/hello"),
47+
testing_framework::Request::new(Method::GET, "/test/hello"),
5048
testing_framework::Response::new_with_body(200, "I'm a teapot"),
5149
)?;
5250
assert_spin_request(
5351
spin,
5452
testing_framework::Request::new(
55-
reqwest::Method::GET,
53+
Method::GET,
5654
"/test/hello/wildcards/should/be/handled",
5755
),
5856
testing_framework::Response::new_with_body(200, "I'm a teapot"),
5957
)?;
6058
assert_spin_request(
6159
spin,
62-
testing_framework::Request::new(reqwest::Method::GET, "/thishsouldfail"),
60+
testing_framework::Request::new(Method::GET, "/thishsouldfail"),
6361
testing_framework::Response::new(404),
6462
)?;
6563
assert_spin_request(
6664
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"),
7166
testing_framework::Response::new_with_body(200, "text for test"),
7267
)
7368
},
@@ -152,7 +147,7 @@ mod integration_tests {
152147
let spin = env.runtime_mut();
153148
assert_spin_request(
154149
spin,
155-
testing_framework::Request::new(reqwest::Method::GET, "/env"),
150+
testing_framework::Request::new(Method::GET, "/env"),
156151
testing_framework::Response::full(
157152
200,
158153
[
@@ -185,7 +180,7 @@ mod integration_tests {
185180
assert_spin_request(
186181
spin,
187182
testing_framework::Request::new(
188-
reqwest::Method::GET,
183+
Method::GET,
189184
&format!("/static/thisshouldbemounted/{name}"),
190185
),
191186
testing_framework::Response::new_with_body(200, content),
@@ -203,10 +198,7 @@ mod integration_tests {
203198
let mut assert_not_found = |path: &str| {
204199
assert_spin_request(
205200
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}")),
210202
testing_framework::Response::new_with_body(404, "Not Found"),
211203
)
212204
};
@@ -233,7 +225,7 @@ mod integration_tests {
233225
let mut test = |lang: &str, body: &str| {
234226
assert_spin_request(
235227
spin,
236-
testing_framework::Request::new(reqwest::Method::GET, &format!("/{lang}")),
228+
testing_framework::Request::new(Method::GET, &format!("/{lang}")),
237229
testing_framework::Response::new_with_body(200, body),
238230
)
239231
};
@@ -279,16 +271,13 @@ Caused by:
279271
let spin = env.runtime_mut();
280272
assert_spin_request(
281273
spin,
282-
testing_framework::Request::new(reqwest::Method::GET, "/test/outbound-allowed"),
274+
testing_framework::Request::new(Method::GET, "/test/outbound-allowed"),
283275
testing_framework::Response::new_with_body(200, "Hello, Fermyon!\n"),
284276
)?;
285277

286278
assert_spin_request(
287279
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"),
292281
testing_framework::Response::new(500),
293282
)?;
294283

@@ -314,7 +303,7 @@ Caused by:
314303
|env| {
315304
let spin = env.runtime_mut();
316305
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);
318307
assert_spin_request(
319308
spin,
320309
request,
@@ -346,7 +335,7 @@ Caused by:
346335
|env| {
347336
let spin = env.runtime_mut();
348337
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);
350339
assert_spin_request(
351340
spin,
352341
request,
@@ -397,7 +386,7 @@ Caused by:
397386
.status();
398387
assert_eq!(status, 200);
399388
let spin = env.runtime_mut();
400-
let request = testing_framework::Request::new(reqwest::Method::GET, "/");
389+
let request = testing_framework::Request::new(Method::GET, "/");
401390
assert_spin_request(
402391
spin,
403392
request,
@@ -596,7 +585,7 @@ Caused by:
596585
)?;
597586
assert_spin_request(
598587
env.runtime_mut(),
599-
testing_framework::Request::new(reqwest::Method::GET, "/"),
588+
testing_framework::Request::new(Method::GET, "/"),
600589
testing_framework::Response::new_with_body(200, "Hello, Fermyon"),
601590
)?;
602591
Ok(())
@@ -627,7 +616,7 @@ Caused by:
627616
assert_spin_request(
628617
env.runtime_mut(),
629618
testing_framework::Request::full(
630-
reqwest::Method::GET,
619+
Method::GET,
631620
"/",
632621
&[("url", &format!("http://127.0.0.1:{port}/",))],
633622
Some(body.as_bytes()),
@@ -936,12 +925,8 @@ route = "/..."
936925
headers.push(("url", &url));
937926
}
938927
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));
945930
assert_spin_request(
946931
spin,
947932
request,
@@ -1008,7 +993,7 @@ route = "/..."
1008993
.map(|(k, v)| (*k, v.as_str()))
1009994
.collect::<Vec<_>>();
1010995
let request = testing_framework::Request::full(
1011-
reqwest::Method::GET,
996+
Method::GET,
1012997
"/hash-all",
1013998
&headers,
1014999
Option::<Vec<u8>>::None,
@@ -1063,7 +1048,7 @@ route = "/..."
10631048
assert_spin_request(
10641049
spin,
10651050
testing_framework::Request::full(
1066-
reqwest::Method::GET,
1051+
Method::GET,
10671052
"/base/echo",
10681053
&[],
10691054
Some("Echo..."),
@@ -1106,7 +1091,7 @@ route = "/..."
11061091
);
11071092
let headers = [("url", service_url.as_str())];
11081093
let request: testing_framework::Request<'_, Vec<u8>> =
1109-
testing_framework::Request::full(reqwest::Method::GET, "/", &headers, None);
1094+
testing_framework::Request::full(Method::GET, "/", &headers, None);
11101095
let expected = testing_framework::Response::new_with_body(200, "Hello, world!");
11111096
assert_spin_request(env.runtime_mut(), request, expected)
11121097
},

0 commit comments

Comments
 (0)