Skip to content

Commit 67f189f

Browse files
authored
Merge pull request #2663 from fermyon/run-conformance
Run conformance tests as part of runtime tests
2 parents c5784b8 + 3a12b68 commit 67f189f

File tree

32 files changed

+74
-302
lines changed

32 files changed

+74
-302
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ runtime-tests = { path = "tests/runtime-tests" }
100100
test-components = { path = "tests/test-components" }
101101
test-codegen-macro = { path = "crates/test-codegen-macro" }
102102
test-environment = { git = "https://github.com/fermyon/conformance-tests", rev = "d2129a3fd73140a76c77f15a030a5273b37cbd11" }
103+
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", rev = "d2129a3fd73140a76c77f15a030a5273b37cbd11" }
104+
conformance = { path = "tests/conformance-tests" }
103105

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

tests/conformance-tests/src/lib.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use anyhow::Context as _;
2+
use testing_framework::runtimes::spin_cli::{SpinCli, SpinConfig};
3+
4+
/// Run a single conformance test against the supplied spin binary.
5+
pub fn run_test(
6+
test: conformance_tests::Test,
7+
spin_binary: &std::path::Path,
8+
) -> anyhow::Result<()> {
9+
let mut services = Vec::new();
10+
for precondition in test.config.preconditions {
11+
match precondition {
12+
conformance_tests::config::Precondition::HttpEcho => {
13+
services.push("http-echo");
14+
}
15+
conformance_tests::config::Precondition::TcpEcho => {
16+
services.push("tcp-echo");
17+
}
18+
conformance_tests::config::Precondition::Redis => services.push("redis"),
19+
conformance_tests::config::Precondition::Mqtt => services.push("mqtt"),
20+
conformance_tests::config::Precondition::KeyValueStore(_) => {}
21+
conformance_tests::config::Precondition::Sqlite => {}
22+
}
23+
}
24+
let env_config = SpinCli::config(
25+
SpinConfig {
26+
binary_path: spin_binary.to_owned(),
27+
spin_up_args: Vec::new(),
28+
app_type: testing_framework::runtimes::SpinAppType::Http,
29+
},
30+
test_environment::services::ServicesConfig::new(services)?,
31+
move |e| {
32+
let mut manifest =
33+
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?;
34+
manifest.substitute(e, |_| None)?;
35+
e.write_file("spin.toml", manifest.contents())?;
36+
e.copy_into(&test.component, test.component.file_name().unwrap())?;
37+
Ok(())
38+
},
39+
);
40+
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(()))?;
41+
for invocation in test.config.invocations {
42+
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
43+
invocation.request.substitute_from_env(&mut env)?;
44+
let spin = env.runtime_mut();
45+
let actual = invocation
46+
.request
47+
.send(|request| spin.make_http_request(request))?;
48+
49+
conformance_tests::assertions::assert_response(&invocation.response, &actual)
50+
.with_context(|| {
51+
format!(
52+
"Failed assertion.\nstdout: {}\nstderr: {}",
53+
spin.stdout().to_owned(),
54+
spin.stderr()
55+
)
56+
})?;
57+
}
58+
Ok(())
59+
}

tests/conformance-tests/src/main.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,7 @@
1-
use anyhow::Context as _;
2-
use testing_framework::runtimes::spin_cli::{SpinCli, SpinConfig};
3-
41
fn main() {
52
let spin_binary: std::path::PathBuf = std::env::args()
63
.nth(1)
74
.expect("expected first argument to be path to spin binary")
85
.into();
9-
conformance_tests::run_tests(move |test| run_test(test, &spin_binary)).unwrap();
10-
}
11-
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");
18-
}
19-
conformance_tests::config::Precondition::TcpEcho => {
20-
services.push("tcp-echo");
21-
}
22-
conformance_tests::config::Precondition::Redis => services.push("redis"),
23-
conformance_tests::config::Precondition::Mqtt => services.push("mqtt"),
24-
conformance_tests::config::Precondition::KeyValueStore(_) => {}
25-
conformance_tests::config::Precondition::Sqlite => {}
26-
}
27-
}
28-
let env_config = SpinCli::config(
29-
SpinConfig {
30-
binary_path: spin_binary.to_owned(),
31-
spin_up_args: Vec::new(),
32-
app_type: testing_framework::runtimes::SpinAppType::Http,
33-
},
34-
test_environment::services::ServicesConfig::new(services)?,
35-
move |e| {
36-
let mut manifest =
37-
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?;
38-
manifest.substitute(e, |_| None)?;
39-
e.write_file("spin.toml", manifest.contents())?;
40-
e.copy_into(&test.component, test.component.file_name().unwrap())?;
41-
Ok(())
42-
},
43-
);
44-
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(()))?;
45-
for invocation in test.config.invocations {
46-
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
47-
invocation.request.substitute_from_env(&mut env)?;
48-
let spin = env.runtime_mut();
49-
let actual = invocation
50-
.request
51-
.send(|request| spin.make_http_request(request))?;
52-
53-
conformance_tests::assertions::assert_response(&invocation.response, &actual)
54-
.with_context(|| {
55-
format!(
56-
"Failed assertion.\nstdout: {}\nstderr: {}",
57-
spin.stdout().to_owned(),
58-
spin.stderr()
59-
)
60-
})?;
61-
}
62-
Ok(())
6+
conformance_tests::run_tests(move |test| conformance::run_test(test, &spin_binary)).unwrap();
637
}

tests/runtime-tests/tests/key-value-no-permission/error.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/runtime-tests/tests/key-value-no-permission/spin.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/runtime-tests/tests/key-value/spin.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/runtime-tests/tests/outbound-mqtt-variable-permission/services

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/runtime-tests/tests/outbound-mqtt-variable-permission/spin.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/runtime-tests/tests/outbound-mqtt/services

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)