Skip to content

Commit e9a24a8

Browse files
committed
Refactoring to conformance-tests
Signed-off-by: Ryan Levick <[email protected]>
1 parent 7f44069 commit e9a24a8

File tree

19 files changed

+196
-1196
lines changed

19 files changed

+196
-1196
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ spin-locked-app = { path = "crates/locked-app" }
6161
spin-manifest = { path = "crates/manifest" }
6262
spin-oci = { path = "crates/oci" }
6363
spin-plugins = { path = "crates/plugins" }
64-
spin-telemetry = { path = "crates/telemetry", features = ["tracing-log-compat"] }
64+
spin-telemetry = { path = "crates/telemetry", features = [
65+
"tracing-log-compat",
66+
] }
6567
spin-templates = { path = "crates/templates" }
6668
spin-trigger = { path = "crates/trigger" }
6769
spin-trigger-http = { path = "crates/trigger-http" }
@@ -97,6 +99,7 @@ redis = "0.24"
9799
runtime-tests = { path = "tests/runtime-tests" }
98100
test-components = { path = "tests/test-components" }
99101
test-codegen-macro = { path = "crates/test-codegen-macro" }
102+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "testing-environment" }
100103

101104
[build-dependencies]
102105
cargo-target-dep = { git = "https://github.com/fermyon/cargo-target-dep", rev = "482f269eceb7b1a7e8fc618bf8c082dd24979cf1" }
@@ -117,16 +120,23 @@ llm-metal = ["llm", "spin-trigger-http/llm-metal"]
117120
llm-cublas = ["llm", "spin-trigger-http/llm-cublas"]
118121

119122
[workspace]
120-
members = ["crates/*", "tests/conformance-tests", "tests/runtime-tests", "tests/testing-framework"]
123+
members = [
124+
"crates/*",
125+
"tests/conformance-tests",
126+
"tests/runtime-tests",
127+
"tests/testing-framework",
128+
]
121129

122130
[workspace.dependencies]
123131
anyhow = "1.0.75"
124132
http-body-util = "0.1.0"
125133
hyper = { version = "1.0.0", features = ["full"] }
126-
reqwest = { version = "0.11", features = ["stream", "blocking"] }
134+
reqwest = { version = "0.12", features = ["stream", "blocking"] }
127135
tracing = { version = "0.1", features = ["log"] }
128136

129-
wasi-common-preview1 = { version = "21.0.1", package = "wasi-common", features = ["tokio"] }
137+
wasi-common-preview1 = { version = "21.0.1", package = "wasi-common", features = [
138+
"tokio",
139+
] }
130140
wasmtime = "21.0.1"
131141
wasmtime-wasi = "21.0.1"
132142
wasmtime-wasi-http = "21.0.1"

tests/conformance-tests/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +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" }
14+
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", branch = "testing-environment" }
15+
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "testing-environment" }
1516

1617
[lints]
1718
workspace = true

tests/conformance-tests/src/main.rs

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,38 @@
1+
use testing_framework::runtimes::spin_cli::SpinCli;
2+
13
fn main() {
24
let spin_binary: std::path::PathBuf = std::env::args()
3-
.skip(1)
4-
.next()
5+
.nth(1)
56
.expect("expected first argument to be path to spin binary")
67
.into();
78
let tests_dir = conformance_tests::download_tests().unwrap();
89

910
for test in conformance_tests::tests(&tests_dir).unwrap() {
10-
let env_config = testing_framework::TestEnvironmentConfig::spin(
11+
let env_config = SpinCli::config(
1112
spin_binary.clone(),
1213
[],
1314
move |e| {
1415
e.copy_into(&test.manifest, "spin.toml")?;
1516
e.copy_into(&test.component, test.component.file_name().unwrap())?;
1617
Ok(())
1718
},
18-
testing_framework::ServicesConfig::none(),
19+
test_environment::services::ServicesConfig::none(),
1920
testing_framework::runtimes::SpinAppType::Http,
2021
);
21-
let mut env = testing_framework::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
22+
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
2223
let spin = env.runtime_mut();
2324
for invocation in test.config.invocations {
2425
let conformance_tests::config::Invocation::Http(invocation) = invocation;
25-
let headers = invocation
26+
let actual = invocation
2627
.request
27-
.headers
28-
.iter()
29-
.map(|h| (h.name.as_str(), h.value.as_str()))
30-
.collect::<Vec<_>>();
31-
let request = testing_framework::http::Request::full(
32-
match invocation.request.method {
33-
conformance_tests::config::Method::GET => testing_framework::http::Method::GET,
34-
conformance_tests::config::Method::POST => {
35-
testing_framework::http::Method::POST
36-
}
37-
},
38-
&invocation.request.path,
39-
&headers,
40-
invocation.request.body,
41-
);
42-
let response = spin.make_http_request(request).unwrap();
43-
let stderr = spin.stderr();
44-
let body = String::from_utf8(response.body())
45-
.unwrap_or_else(|_| String::from("invalid utf-8"));
46-
assert_eq!(
47-
response.status(),
48-
invocation.response.status,
49-
"request to Spin failed\nstderr:\n{stderr}\nbody:\n{body}",
50-
);
51-
52-
let mut actual_headers = response
53-
.headers()
54-
.iter()
55-
.map(|(k, v)| (k.to_lowercase(), v.to_lowercase()))
56-
.collect::<std::collections::HashMap<_, _>>();
57-
for expected_header in invocation.response.headers {
58-
let expected_name = expected_header.name.to_lowercase();
59-
let expected_value = expected_header.value.map(|v| v.to_lowercase());
60-
let actual_value = actual_headers.remove(&expected_name);
61-
let Some(actual_value) = actual_value.as_deref() else {
62-
if expected_header.optional {
63-
continue;
64-
} else {
65-
panic!(
66-
"expected header {name} not found in response",
67-
name = expected_header.name
68-
)
69-
}
70-
};
71-
if let Some(expected_value) = expected_value {
72-
assert_eq!(actual_value, expected_value);
73-
}
74-
}
75-
if !actual_headers.is_empty() {
76-
panic!("unexpected headers: {actual_headers:?}");
77-
}
78-
79-
if let Some(expected_body) = invocation.response.body {
80-
assert_eq!(body, expected_body);
28+
.send(|request| spin.make_http_request(request))
29+
.unwrap();
30+
if let Err(e) =
31+
conformance_tests::assertions::assert_response(invocation.response, actual)
32+
{
33+
eprintln!("Test failed: {e}");
34+
eprintln!("stderr: {}", spin.stderr());
35+
std::process::exit(1);
8136
}
8237
}
8338
}

0 commit comments

Comments
 (0)