Skip to content

Commit ca22ddc

Browse files
authored
Merge pull request #2675 from fermyon/conformance-test-try-again
2 parents ca1dcd3 + 190f313 commit ca22ddc

File tree

33 files changed

+95
-302
lines changed

33 files changed

+95
-302
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ jobs:
170170
- name: Run Integration Tests
171171
run: |
172172
make test-integration
173+
env:
174+
SPIN_CONFORMANCE_TESTS_DOCKER_OPT_OUT: true
173175
# Only run integration tests on macOS as they will be run on ubuntu separately
174176
if: ${{ matrix.runner == 'macos-14' }}
175177

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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 => {
19+
if should_run_docker_based_tests() {
20+
services.push("redis")
21+
} else {
22+
// Skip the test if docker is not installed.
23+
return Ok(());
24+
}
25+
}
26+
conformance_tests::config::Precondition::Mqtt => {
27+
if should_run_docker_based_tests() {
28+
services.push("mqtt")
29+
} else {
30+
// Skip the test if docker is not installed.
31+
return Ok(());
32+
}
33+
}
34+
conformance_tests::config::Precondition::KeyValueStore(_) => {}
35+
conformance_tests::config::Precondition::Sqlite => {}
36+
}
37+
}
38+
let env_config = SpinCli::config(
39+
SpinConfig {
40+
binary_path: spin_binary.to_owned(),
41+
spin_up_args: Vec::new(),
42+
app_type: testing_framework::runtimes::SpinAppType::Http,
43+
},
44+
test_environment::services::ServicesConfig::new(services)?,
45+
move |e| {
46+
let mut manifest =
47+
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?;
48+
manifest.substitute(e, |_| None)?;
49+
e.write_file("spin.toml", manifest.contents())?;
50+
e.copy_into(&test.component, test.component.file_name().unwrap())?;
51+
Ok(())
52+
},
53+
);
54+
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(()))?;
55+
for invocation in test.config.invocations {
56+
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
57+
invocation.request.substitute_from_env(&mut env)?;
58+
let spin = env.runtime_mut();
59+
let actual = invocation
60+
.request
61+
.send(|request| spin.make_http_request(request))?;
62+
63+
conformance_tests::assertions::assert_response(&invocation.response, &actual)
64+
.with_context(|| {
65+
format!(
66+
"Failed assertion.\nstdout: {}\nstderr: {}",
67+
spin.stdout().to_owned(),
68+
spin.stderr()
69+
)
70+
})?;
71+
}
72+
Ok(())
73+
}
74+
75+
/// Whether or not docker is installed on the system.
76+
fn should_run_docker_based_tests() -> bool {
77+
std::env::var("SPIN_CONFORMANCE_TESTS_DOCKER_OPT_OUT").is_err()
78+
}

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.

0 commit comments

Comments
 (0)