Skip to content

Commit a6ff1e6

Browse files
committed
Download tests from releases
Signed-off-by: Ryan Levick <[email protected]>
1 parent 1a84903 commit a6ff1e6

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

Cargo.lock

Lines changed: 4 additions & 0 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ rust-version.workspace = true
1010

1111
[dependencies]
1212
anyhow = "1.0"
13+
flate2 = "1.0"
1314
json5 = "0.4.1"
15+
reqwest = { version = "0.12", features = ["blocking"] }
1416
serde = "1.0"
17+
tar = "0.4.40"
1518
testing-framework = { path = "../testing-framework" }
1619

1720
[lints]

tests/conformance-tests/src/main.rs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
use std::collections::HashMap;
2-
31
use anyhow::Context as _;
42

53
fn main() {
6-
let dir = std::fs::read_dir("/Users/rylev/Code/fermyon/conformance-test/tests").unwrap();
7-
for entry in dir {
4+
let tests_dir = download_tests();
5+
6+
for entry in std::fs::read_dir(tests_dir).unwrap() {
87
let entry = entry.unwrap();
8+
if !entry.path().is_dir() {
9+
continue;
10+
}
911
let spin_binary = "/Users/rylev/.local/bin/spin".into();
1012
let test_config = std::fs::read_to_string(entry.path().join("test.json5")).unwrap();
1113
let test_config: TestConfig = json5::from_str(&test_config).unwrap();
12-
let config = testing_framework::TestEnvironmentConfig::spin(
14+
let env_config = testing_framework::TestEnvironmentConfig::spin(
1315
spin_binary,
14-
["-f".into(), entry.path().to_str().unwrap().into()],
16+
[],
1517
move |e| {
18+
e.copy_into(entry.path().join("target"), "target")
19+
.context("failed to copy target directory")?;
1620
e.copy_into(entry.path().join("spin.toml"), "spin.toml")
1721
.context("failed to copy spin.toml")?;
18-
let mut cmd = std::process::Command::new("spin");
19-
cmd.env("CARGO_TARGET_DIR", entry.path().join("target"));
20-
cmd.args(["build", "-f", entry.path().to_str().unwrap()]);
21-
e.run_in(&mut cmd)?;
2222
Ok(())
2323
},
2424
testing_framework::ServicesConfig::none(),
2525
testing_framework::runtimes::SpinAppType::Http,
2626
);
27-
let mut env = testing_framework::TestEnvironment::up(config, |_| Ok(())).unwrap();
27+
let mut env = testing_framework::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
2828
let spin = env.runtime_mut();
2929
for invocation in test_config.invocations {
30+
let Invocation::Http(invocation) = invocation;
3031
let headers = invocation
3132
.request
3233
.headers
@@ -53,7 +54,7 @@ fn main() {
5354
.headers()
5455
.iter()
5556
.map(|(k, v)| (k.to_lowercase(), v.to_lowercase()))
56-
.collect::<HashMap<_, _>>();
57+
.collect::<std::collections::HashMap<_, _>>();
5758
for expected_header in invocation.response.headers {
5859
let expected_name = expected_header.name.to_lowercase();
5960
let expected_value = expected_header.value.map(|v| v.to_lowercase());
@@ -83,13 +84,45 @@ fn main() {
8384
}
8485
}
8586

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
86112
#[derive(Debug, serde::Deserialize)]
87113
struct TestConfig {
88114
invocations: Vec<Invocation>,
89115
}
90116

91117
#[derive(Debug, serde::Deserialize)]
92-
struct Invocation {
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 {
93126
request: Request,
94127
response: Response,
95128
}

0 commit comments

Comments
 (0)