Skip to content

Commit cadd38a

Browse files
committed
Use new test runner
Signed-off-by: Ryan Levick <[email protected]>
1 parent 46cda71 commit cadd38a

File tree

6 files changed

+65
-55
lines changed

6 files changed

+65
-55
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ redis = "0.24"
9999
runtime-tests = { path = "tests/runtime-tests" }
100100
test-components = { path = "tests/test-components" }
101101
test-codegen-macro = { path = "crates/test-codegen-macro" }
102-
test-environment = { git = "https://github.com/fermyon/conformance-tests" }
102+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "libtest_mimic" }
103103

104104
[build-dependencies]
105105
cargo-target-dep = { git = "https://github.com/fermyon/cargo-target-dep", rev = "482f269eceb7b1a7e8fc618bf8c082dd24979cf1" }

tests/conformance-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ rust-version.workspace = true
1111
[dependencies]
1212
anyhow = "1.0"
1313
testing-framework = { path = "../testing-framework" }
14-
conformance-tests = { git = "https://github.com/fermyon/conformance-tests" }
15-
test-environment = { git = "https://github.com/fermyon/conformance-tests" }
14+
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", branch = "libtest_mimic" }
15+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "libtest_mimic" }
1616

1717
[lints]
1818
workspace = true

tests/conformance-tests/src/main.rs

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,44 @@ fn main() {
55
.nth(1)
66
.expect("expected first argument to be path to spin binary")
77
.into();
8-
let tests_dir = conformance_tests::download_tests().unwrap();
8+
conformance_tests::run_tests(move |test| run_test(test, &spin_binary)).unwrap();
9+
}
910

10-
for test in conformance_tests::tests(&tests_dir).unwrap() {
11-
println!("Running test '{}'", test.name);
12-
let mut services = Vec::new();
13-
for precondition in test.config.preconditions {
14-
match precondition {
15-
conformance_tests::config::Precondition::HttpEcho => {
16-
services.push("http-echo".into());
17-
}
18-
conformance_tests::config::Precondition::KeyValueStore(_) => {}
19-
}
20-
}
21-
let env_config = SpinCli::config(
22-
SpinConfig {
23-
binary_path: spin_binary.clone(),
24-
spin_up_args: Vec::new(),
25-
app_type: testing_framework::runtimes::SpinAppType::Http,
26-
},
27-
test_environment::services::ServicesConfig::new(services).unwrap(),
28-
move |e| {
29-
let mut manifest =
30-
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)
31-
.unwrap();
32-
manifest.substitute(e, |_| None).unwrap();
33-
e.write_file("spin.toml", manifest.contents())?;
34-
e.copy_into(&test.component, test.component.file_name().unwrap())?;
35-
Ok(())
36-
},
37-
);
38-
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
39-
for invocation in test.config.invocations {
40-
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
41-
invocation.request.substitute_from_env(&mut env).unwrap();
42-
let spin = env.runtime_mut();
43-
let actual = invocation
44-
.request
45-
.send(|request| spin.make_http_request(request))
46-
.unwrap();
47-
if let Err(e) =
48-
conformance_tests::assertions::assert_response(&invocation.response, &actual)
49-
{
50-
eprintln!("Test '{}' failed: {e}", test.name);
51-
eprintln!("stderr: {}", spin.stderr());
52-
std::process::exit(1);
11+
fn run_test(test: conformance_tests::Test, spin_binary: &std::path::Path) -> anyhow::Result<()> {
12+
let mut services = Vec::new();
13+
for precondition in test.config.preconditions {
14+
match precondition {
15+
conformance_tests::config::Precondition::HttpEcho => {
16+
services.push("http-echo".into());
5317
}
18+
conformance_tests::config::Precondition::KeyValueStore(_) => {}
5419
}
5520
}
56-
println!("All tests passed!")
21+
let env_config = SpinCli::config(
22+
SpinConfig {
23+
binary_path: spin_binary.to_owned(),
24+
spin_up_args: Vec::new(),
25+
app_type: testing_framework::runtimes::SpinAppType::Http,
26+
},
27+
test_environment::services::ServicesConfig::new(services)?,
28+
move |e| {
29+
let mut manifest =
30+
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?;
31+
manifest.substitute(e, |_| None)?;
32+
e.write_file("spin.toml", manifest.contents())?;
33+
e.copy_into(&test.component, test.component.file_name().unwrap())?;
34+
Ok(())
35+
},
36+
);
37+
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(()))?;
38+
for invocation in test.config.invocations {
39+
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
40+
invocation.request.substitute_from_env(&mut env)?;
41+
let spin = env.runtime_mut();
42+
let actual = invocation
43+
.request
44+
.send(|request| spin.make_http_request(request))?;
45+
conformance_tests::assertions::assert_response(&invocation.response, &actual)?;
46+
}
47+
Ok(())
5748
}

tests/runtime-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ anyhow = "1.0"
1313
env_logger = "0.10.0"
1414
log = "0.4"
1515
testing-framework = { path = "../testing-framework" }
16-
test-environment = { git = "https://github.com/fermyon/conformance-tests" }
16+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "libtest_mimic" }
1717
test-components = { path = "../test-components" }

tests/testing-framework/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ nix = "0.26.1"
1313
regex = "1.10.2"
1414
reqwest = { workspace = true }
1515
temp-dir = "0.1.11"
16-
test-environment = { git = "https://github.com/fermyon/conformance-tests" }
16+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "libtest_mimic" }
1717
spin-trigger-http = { path = "../../crates/trigger-http" }
1818
spin-http = { path = "../../crates/http" }
1919
spin-trigger = { path = "../../crates/trigger" }

0 commit comments

Comments
 (0)