Skip to content

Commit 444adba

Browse files
authored
Merge pull request #2591 from fermyon/conformance-tests-update2
Conformance Tests Update
2 parents fb215b0 + 2d90ae2 commit 444adba

File tree

6 files changed

+77
-46
lines changed

6 files changed

+77
-46
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 = "main" }
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 = "main" }
15+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "main" }
1616

1717
[lints]
1818
workspace = true

tests/conformance-tests/src/main.rs

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,60 @@
1+
use anyhow::Context as _;
12
use testing_framework::runtimes::spin_cli::{SpinCli, SpinConfig};
23

34
fn main() {
45
let spin_binary: std::path::PathBuf = std::env::args()
56
.nth(1)
67
.expect("expected first argument to be path to spin binary")
78
.into();
8-
let tests_dir = conformance_tests::download_tests().unwrap();
9+
conformance_tests::run_tests(move |test| run_test(test, &spin_binary)).unwrap();
10+
}
911

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

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 = "main" }
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 = "main" }
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)