Skip to content

Commit 62ef9a6

Browse files
committed
Move config into conformance tests repo
Signed-off-by: Ryan Levick <[email protected]>
1 parent a6ff1e6 commit 62ef9a6

File tree

3 files changed

+25
-120
lines changed

3 files changed

+25
-120
lines changed

Cargo.lock

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conformance-tests/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "conformance-tests"
2+
name = "conformance"
33
version.workspace = true
44
authors.workspace = true
55
edition.workspace = true
@@ -10,12 +10,8 @@ rust-version.workspace = true
1010

1111
[dependencies]
1212
anyhow = "1.0"
13-
flate2 = "1.0"
14-
json5 = "0.4.1"
15-
reqwest = { version = "0.12", features = ["blocking"] }
16-
serde = "1.0"
17-
tar = "0.4.40"
1813
testing-framework = { path = "../testing-framework" }
14+
conformance-tests = { git = "https://github.com/fermyon/conformance-tests" }
1915

2016
[lints]
2117
workspace = true

tests/conformance-tests/src/main.rs

Lines changed: 12 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
use anyhow::Context as _;
2-
31
fn main() {
4-
let tests_dir = download_tests();
2+
let tests_dir = conformance_tests::download_tests().unwrap();
53

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() {
115
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();
146
let env_config = testing_framework::TestEnvironmentConfig::spin(
157
spin_binary,
168
[],
179
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())?;
2212
Ok(())
2313
},
2414
testing_framework::ServicesConfig::none(),
2515
testing_framework::runtimes::SpinAppType::Http,
2616
);
2717
let mut env = testing_framework::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
2818
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;
3121
let headers = invocation
3222
.request
3323
.headers
3424
.iter()
3525
.map(|h| (h.name.as_str(), h.value.as_str()))
3626
.collect::<Vec<_>>();
3727
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+
},
3934
&invocation.request.path,
4035
&headers,
4136
invocation.request.body,
@@ -83,98 +78,3 @@ fn main() {
8378
}
8479
}
8580
}
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

Comments
 (0)