|
| 1 | +use testing_framework::runtimes::spin_cli::SpinCli; |
| 2 | + |
1 | 3 | fn main() {
|
2 | 4 | let spin_binary: std::path::PathBuf = std::env::args()
|
3 |
| - .skip(1) |
4 |
| - .next() |
| 5 | + .nth(1) |
5 | 6 | .expect("expected first argument to be path to spin binary")
|
6 | 7 | .into();
|
7 | 8 | let tests_dir = conformance_tests::download_tests().unwrap();
|
8 | 9 |
|
9 | 10 | for test in conformance_tests::tests(&tests_dir).unwrap() {
|
10 |
| - let env_config = testing_framework::TestEnvironmentConfig::spin( |
| 11 | + let env_config = SpinCli::config( |
11 | 12 | spin_binary.clone(),
|
12 | 13 | [],
|
13 | 14 | move |e| {
|
14 | 15 | e.copy_into(&test.manifest, "spin.toml")?;
|
15 | 16 | e.copy_into(&test.component, test.component.file_name().unwrap())?;
|
16 | 17 | Ok(())
|
17 | 18 | },
|
18 |
| - testing_framework::ServicesConfig::none(), |
| 19 | + test_environment::services::ServicesConfig::none(), |
19 | 20 | testing_framework::runtimes::SpinAppType::Http,
|
20 | 21 | );
|
21 |
| - let mut env = testing_framework::TestEnvironment::up(env_config, |_| Ok(())).unwrap(); |
| 22 | + let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(())).unwrap(); |
22 | 23 | let spin = env.runtime_mut();
|
23 | 24 | for invocation in test.config.invocations {
|
24 | 25 | let conformance_tests::config::Invocation::Http(invocation) = invocation;
|
25 |
| - let headers = invocation |
| 26 | + let actual = invocation |
26 | 27 | .request
|
27 |
| - .headers |
28 |
| - .iter() |
29 |
| - .map(|h| (h.name.as_str(), h.value.as_str())) |
30 |
| - .collect::<Vec<_>>(); |
31 |
| - let request = testing_framework::http::Request::full( |
32 |
| - match invocation.request.method { |
33 |
| - conformance_tests::config::Method::GET => testing_framework::http::Method::GET, |
34 |
| - conformance_tests::config::Method::POST => { |
35 |
| - testing_framework::http::Method::POST |
36 |
| - } |
37 |
| - }, |
38 |
| - &invocation.request.path, |
39 |
| - &headers, |
40 |
| - invocation.request.body, |
41 |
| - ); |
42 |
| - let response = spin.make_http_request(request).unwrap(); |
43 |
| - let stderr = spin.stderr(); |
44 |
| - let body = String::from_utf8(response.body()) |
45 |
| - .unwrap_or_else(|_| String::from("invalid utf-8")); |
46 |
| - assert_eq!( |
47 |
| - response.status(), |
48 |
| - invocation.response.status, |
49 |
| - "request to Spin failed\nstderr:\n{stderr}\nbody:\n{body}", |
50 |
| - ); |
51 |
| - |
52 |
| - let mut actual_headers = response |
53 |
| - .headers() |
54 |
| - .iter() |
55 |
| - .map(|(k, v)| (k.to_lowercase(), v.to_lowercase())) |
56 |
| - .collect::<std::collections::HashMap<_, _>>(); |
57 |
| - for expected_header in invocation.response.headers { |
58 |
| - let expected_name = expected_header.name.to_lowercase(); |
59 |
| - let expected_value = expected_header.value.map(|v| v.to_lowercase()); |
60 |
| - let actual_value = actual_headers.remove(&expected_name); |
61 |
| - let Some(actual_value) = actual_value.as_deref() else { |
62 |
| - if expected_header.optional { |
63 |
| - continue; |
64 |
| - } else { |
65 |
| - panic!( |
66 |
| - "expected header {name} not found in response", |
67 |
| - name = expected_header.name |
68 |
| - ) |
69 |
| - } |
70 |
| - }; |
71 |
| - if let Some(expected_value) = expected_value { |
72 |
| - assert_eq!(actual_value, expected_value); |
73 |
| - } |
74 |
| - } |
75 |
| - if !actual_headers.is_empty() { |
76 |
| - panic!("unexpected headers: {actual_headers:?}"); |
77 |
| - } |
78 |
| - |
79 |
| - if let Some(expected_body) = invocation.response.body { |
80 |
| - assert_eq!(body, expected_body); |
| 28 | + .send(|request| spin.make_http_request(request)) |
| 29 | + .unwrap(); |
| 30 | + if let Err(e) = |
| 31 | + conformance_tests::assertions::assert_response(invocation.response, actual) |
| 32 | + { |
| 33 | + eprintln!("Test failed: {e}"); |
| 34 | + eprintln!("stderr: {}", spin.stderr()); |
| 35 | + std::process::exit(1); |
81 | 36 | }
|
82 | 37 | }
|
83 | 38 | }
|
|
0 commit comments