-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2591 from fermyon/conformance-tests-update2
Conformance Tests Update
- Loading branch information
Showing
6 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,60 @@ | ||
use anyhow::Context as _; | ||
use testing_framework::runtimes::spin_cli::{SpinCli, SpinConfig}; | ||
|
||
fn main() { | ||
let spin_binary: std::path::PathBuf = std::env::args() | ||
.nth(1) | ||
.expect("expected first argument to be path to spin binary") | ||
.into(); | ||
let tests_dir = conformance_tests::download_tests().unwrap(); | ||
conformance_tests::run_tests(move |test| run_test(test, &spin_binary)).unwrap(); | ||
} | ||
|
||
for test in conformance_tests::tests(&tests_dir).unwrap() { | ||
println!("Running test '{}'", test.name); | ||
let env_config = SpinCli::config( | ||
SpinConfig { | ||
binary_path: spin_binary.clone(), | ||
spin_up_args: Vec::new(), | ||
app_type: testing_framework::runtimes::SpinAppType::Http, | ||
}, | ||
test_environment::services::ServicesConfig::new(test.config.services).unwrap(), | ||
move |e| { | ||
let mut manifest = | ||
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest) | ||
.unwrap(); | ||
manifest.substitute(e, |_| None).unwrap(); | ||
e.write_file("spin.toml", manifest.contents())?; | ||
e.copy_into(&test.component, test.component.file_name().unwrap())?; | ||
Ok(()) | ||
}, | ||
); | ||
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(())).unwrap(); | ||
for invocation in test.config.invocations { | ||
let conformance_tests::config::Invocation::Http(mut invocation) = invocation; | ||
invocation.request.substitute_from_env(&mut env).unwrap(); | ||
let spin = env.runtime_mut(); | ||
let actual = invocation | ||
.request | ||
.send(|request| spin.make_http_request(request)) | ||
.unwrap(); | ||
if let Err(e) = | ||
conformance_tests::assertions::assert_response(&invocation.response, &actual) | ||
{ | ||
eprintln!("Test '{}' failed: {e}", test.name); | ||
eprintln!("stderr: {}", spin.stderr()); | ||
std::process::exit(1); | ||
fn run_test(test: conformance_tests::Test, spin_binary: &std::path::Path) -> anyhow::Result<()> { | ||
let mut services = Vec::new(); | ||
for precondition in test.config.preconditions { | ||
match precondition { | ||
conformance_tests::config::Precondition::HttpEcho => { | ||
services.push("http-echo".into()); | ||
} | ||
conformance_tests::config::Precondition::TcpEcho => { | ||
services.push("tcp-echo".into()); | ||
} | ||
conformance_tests::config::Precondition::KeyValueStore(_) => {} | ||
} | ||
} | ||
println!("All tests passed!") | ||
let env_config = SpinCli::config( | ||
SpinConfig { | ||
binary_path: spin_binary.to_owned(), | ||
spin_up_args: Vec::new(), | ||
app_type: testing_framework::runtimes::SpinAppType::Http, | ||
}, | ||
test_environment::services::ServicesConfig::new(services)?, | ||
move |e| { | ||
let mut manifest = | ||
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?; | ||
manifest.substitute(e, |_| None)?; | ||
e.write_file("spin.toml", manifest.contents())?; | ||
e.copy_into(&test.component, test.component.file_name().unwrap())?; | ||
Ok(()) | ||
}, | ||
); | ||
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(()))?; | ||
for invocation in test.config.invocations { | ||
let conformance_tests::config::Invocation::Http(mut invocation) = invocation; | ||
invocation.request.substitute_from_env(&mut env)?; | ||
let spin = env.runtime_mut(); | ||
let actual = invocation | ||
.request | ||
.send(|request| spin.make_http_request(request))?; | ||
|
||
conformance_tests::assertions::assert_response(&invocation.response, &actual) | ||
.with_context(|| { | ||
format!( | ||
"Failed assertion.\nstdout: {}\nstderr: {}", | ||
spin.stdout().to_owned(), | ||
spin.stderr() | ||
) | ||
})?; | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters