|
1 |
| -use anyhow::Context as _; |
2 |
| - |
3 | 1 | fn main() {
|
4 |
| - let tests_dir = download_tests(); |
| 2 | + let tests_dir = conformance_tests::download_tests().unwrap(); |
5 | 3 |
|
6 |
| - for entry in std::fs::read_dir(tests_dir).unwrap() { |
7 |
| - let entry = entry.unwrap(); |
8 |
| - if !entry.path().is_dir() { |
9 |
| - continue; |
10 |
| - } |
| 4 | + for test in conformance_tests::tests(&tests_dir).unwrap() { |
11 | 5 | let spin_binary = "/Users/rylev/.local/bin/spin".into();
|
12 |
| - let test_config = std::fs::read_to_string(entry.path().join("test.json5")).unwrap(); |
13 |
| - let test_config: TestConfig = json5::from_str(&test_config).unwrap(); |
14 | 6 | let env_config = testing_framework::TestEnvironmentConfig::spin(
|
15 | 7 | spin_binary,
|
16 | 8 | [],
|
17 | 9 | move |e| {
|
18 |
| - e.copy_into(entry.path().join("target"), "target") |
19 |
| - .context("failed to copy target directory")?; |
20 |
| - e.copy_into(entry.path().join("spin.toml"), "spin.toml") |
21 |
| - .context("failed to copy spin.toml")?; |
| 10 | + e.copy_into(&test.manifest, "spin.toml")?; |
| 11 | + e.copy_into(&test.component, test.component.file_name().unwrap())?; |
22 | 12 | Ok(())
|
23 | 13 | },
|
24 | 14 | testing_framework::ServicesConfig::none(),
|
25 | 15 | testing_framework::runtimes::SpinAppType::Http,
|
26 | 16 | );
|
27 | 17 | let mut env = testing_framework::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
|
28 | 18 | let spin = env.runtime_mut();
|
29 |
| - for invocation in test_config.invocations { |
30 |
| - let Invocation::Http(invocation) = invocation; |
| 19 | + for invocation in test.config.invocations { |
| 20 | + let conformance_tests::config::Invocation::Http(invocation) = invocation; |
31 | 21 | let headers = invocation
|
32 | 22 | .request
|
33 | 23 | .headers
|
34 | 24 | .iter()
|
35 | 25 | .map(|h| (h.name.as_str(), h.value.as_str()))
|
36 | 26 | .collect::<Vec<_>>();
|
37 | 27 | let request = testing_framework::http::Request::full(
|
38 |
| - invocation.request.method.into(), |
| 28 | + match invocation.request.method { |
| 29 | + conformance_tests::config::Method::GET => testing_framework::http::Method::GET, |
| 30 | + conformance_tests::config::Method::POST => { |
| 31 | + testing_framework::http::Method::POST |
| 32 | + } |
| 33 | + }, |
39 | 34 | &invocation.request.path,
|
40 | 35 | &headers,
|
41 | 36 | invocation.request.body,
|
@@ -83,98 +78,3 @@ fn main() {
|
83 | 78 | }
|
84 | 79 | }
|
85 | 80 | }
|
86 |
| - |
87 |
| -/// Download the conformance tests and return the path to the directory where they are written to |
88 |
| -fn download_tests() -> std::path::PathBuf { |
89 |
| - let response = reqwest::blocking::get( |
90 |
| - "https://github.com/fermyon/conformance-tests/releases/download/canary/tests.tar.gz", |
91 |
| - ) |
92 |
| - .unwrap() |
93 |
| - .error_for_status() |
94 |
| - .unwrap(); |
95 |
| - let response = flate2::read::GzDecoder::new(response); |
96 |
| - let dir = std::env::temp_dir().join("conformance-tests"); |
97 |
| - for entry in tar::Archive::new(response).entries().unwrap() { |
98 |
| - let mut entry = entry.unwrap(); |
99 |
| - if entry.header().entry_type() != tar::EntryType::Regular { |
100 |
| - continue; |
101 |
| - } |
102 |
| - let path = dir.join(entry.path().unwrap()); |
103 |
| - let parent_dir = path.parent().unwrap(); |
104 |
| - std::fs::create_dir_all(&parent_dir).unwrap(); |
105 |
| - let mut file = std::fs::File::create(&path).unwrap(); |
106 |
| - std::io::copy(&mut entry, &mut file).unwrap(); |
107 |
| - } |
108 |
| - dir |
109 |
| -} |
110 |
| - |
111 |
| -/// The configuration of a conformance test |
112 |
| -#[derive(Debug, serde::Deserialize)] |
113 |
| -struct TestConfig { |
114 |
| - invocations: Vec<Invocation>, |
115 |
| -} |
116 |
| - |
117 |
| -#[derive(Debug, serde::Deserialize)] |
118 |
| -#[serde(untagged)] |
119 |
| -enum Invocation { |
120 |
| - Http(HttpInvocation), |
121 |
| -} |
122 |
| - |
123 |
| -/// An invocation of the runtime |
124 |
| -#[derive(Debug, serde::Deserialize)] |
125 |
| -struct HttpInvocation { |
126 |
| - request: Request, |
127 |
| - response: Response, |
128 |
| -} |
129 |
| - |
130 |
| -#[derive(Debug, serde::Deserialize)] |
131 |
| -struct Request { |
132 |
| - #[serde(default)] |
133 |
| - method: Method, |
134 |
| - path: String, |
135 |
| - #[serde(default)] |
136 |
| - headers: Vec<RequestHeader>, |
137 |
| - #[serde(default)] |
138 |
| - body: Option<String>, |
139 |
| -} |
140 |
| - |
141 |
| -#[derive(Debug, serde::Deserialize)] |
142 |
| -struct Response { |
143 |
| - #[serde(default = "default_status")] |
144 |
| - status: u16, |
145 |
| - headers: Vec<ResponseHeader>, |
146 |
| - body: Option<String>, |
147 |
| -} |
148 |
| -#[derive(Debug, serde::Deserialize)] |
149 |
| -struct RequestHeader { |
150 |
| - name: String, |
151 |
| - value: String, |
152 |
| -} |
153 |
| - |
154 |
| -#[derive(Debug, serde::Deserialize)] |
155 |
| -struct ResponseHeader { |
156 |
| - name: String, |
157 |
| - value: Option<String>, |
158 |
| - #[serde(default)] |
159 |
| - optional: bool, |
160 |
| -} |
161 |
| - |
162 |
| -#[derive(Debug, serde::Deserialize, Default)] |
163 |
| -enum Method { |
164 |
| - #[default] |
165 |
| - GET, |
166 |
| - POST, |
167 |
| -} |
168 |
| - |
169 |
| -impl From<Method> for testing_framework::http::Method { |
170 |
| - fn from(method: Method) -> Self { |
171 |
| - match method { |
172 |
| - Method::GET => testing_framework::http::Method::GET, |
173 |
| - Method::POST => testing_framework::http::Method::POST, |
174 |
| - } |
175 |
| - } |
176 |
| -} |
177 |
| - |
178 |
| -fn default_status() -> u16 { |
179 |
| - 200 |
180 |
| -} |
0 commit comments