Skip to content

Commit 7a6b81b

Browse files
authored
Merge pull request #2223 from fermyon/e2e-testing-framework
E2E testing using testing framework
2 parents b7d6576 + 2efcbdd commit 7a6b81b

File tree

37 files changed

+557
-2800
lines changed

37 files changed

+557
-2800
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ e2e-testing = { path = "crates/e2e-testing" }
9292
http-body-util = { workspace = true }
9393
testing-framework = { path = "tests/testing-framework" }
9494
hyper-util = { version = "0.1.2", features = ["tokio"] }
95+
redis = "0.24"
9596
runtime-tests = { path = "tests/runtime-tests" }
9697
test-components = { path = "tests/test-components" }
9798
test-codegen-macro = { path = "crates/test-codegen-macro" }
@@ -133,8 +134,12 @@ tracing = { version = "0.1", features = ["log"] }
133134

134135
# TODO: update to final 17.0.0 release once it's available
135136
wasi-common-preview1 = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0", package = "wasi-common" }
136-
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0", features = ["component-model"] }
137-
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0", features = ["tokio"] }
137+
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0", features = [
138+
"component-model",
139+
] }
140+
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0", features = [
141+
"tokio",
142+
] }
138143
wasmtime-wasi-http = { git = "https://github.com/bytecodealliance/wasmtime", branch = "release-17.0.0" }
139144

140145
spin-componentize = { git = "https://github.com/fermyon/spin-componentize", rev = "191789170abde10cd55590466c0660dd6c7d472a" }

tests/integration.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ mod integration_tests {
4141
"{}/{}",
4242
RUST_HTTP_INTEGRATION_TEST, DEFAULT_MANIFEST_LOCATION
4343
),
44-
|spin| {
44+
|env| {
45+
let spin = env.runtime_mut();
4546
assert_spin_status(spin, "/test/hello", 200)?;
4647
assert_spin_status(spin, "/test/hello/wildcards/should/be/handled", 200)?;
4748
assert_spin_status(spin, "/thisshouldfail", 404)?;
@@ -57,7 +58,8 @@ mod integration_tests {
5758
fn test_duplicate_rust_local() -> Result<()> {
5859
integration_test(
5960
format!("{}/{}", RUST_HTTP_INTEGRATION_TEST, "double-trouble.toml"),
60-
|spin| {
61+
|env| {
62+
let spin = env.runtime_mut();
6163
assert_spin_status(spin, "/route1", 200)?;
6264
assert_spin_status(spin, "/route2", 200)?;
6365
assert_spin_status(spin, "/thisshouldfail", 404)?;
@@ -243,12 +245,15 @@ mod integration_tests {
243245

244246
fn integration_test(
245247
manifest_path: impl Into<PathBuf>,
246-
test: impl FnOnce(&mut testing_framework::Spin) -> testing_framework::TestResult<anyhow::Error>
248+
test: impl FnOnce(
249+
&mut testing_framework::TestEnvironment<testing_framework::Spin>,
250+
) -> testing_framework::TestResult<anyhow::Error>
247251
+ 'static,
248252
) -> anyhow::Result<()> {
249253
let manifest_path = manifest_path.into();
250254
let spin = testing_framework::TestEnvironmentConfig::spin(
251255
spin_binary().into(),
256+
[],
252257
move |env| {
253258
// Copy manifest
254259
let mut template = testing_framework::ManifestTemplate::from_file(manifest_path)?;
@@ -261,17 +266,20 @@ mod integration_tests {
261266
Ok(())
262267
},
263268
testing_framework::ServicesConfig::none(),
269+
testing_framework::SpinMode::Http,
264270
);
265271
let mut env = testing_framework::TestEnvironment::up(spin)?;
266-
Ok(env.test(test)?)
272+
test(&mut env)?;
273+
Ok(())
267274
}
268275

269276
fn assert_spin_status(
270277
spin: &mut testing_framework::Spin,
271278
uri: &str,
272279
status: u16,
273280
) -> testing_framework::TestResult<anyhow::Error> {
274-
let r = spin.make_http_request(reqwest::Method::GET, uri)?;
281+
let r =
282+
spin.make_http_request(testing_framework::Request::new(reqwest::Method::GET, uri))?;
275283
if r.status() != status {
276284
return Err(testing_framework::TestError::Failure(anyhow!(
277285
"Expected status {} for {} but got {}",

tests/runtime-tests/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ impl RuntimeTest<Spin> {
6060
Ok(())
6161
};
6262
let services_config = services_config(&config)?;
63-
let env_config = TestEnvironmentConfig::spin(spin_binary, preboot, services_config);
63+
let env_config = TestEnvironmentConfig::spin(
64+
spin_binary,
65+
[],
66+
preboot,
67+
services_config,
68+
testing_framework::SpinMode::Http,
69+
);
6470
let env = TestEnvironment::up(env_config)?;
6571
Ok(Self {
6672
test_path: config.test_path,
@@ -84,7 +90,7 @@ impl RuntimeTest<Spin> {
8490
}
8591
};
8692
}
87-
let response = self.env.test(test);
93+
let response = test(&mut self.env);
8894
let error_file = self.test_path.join("error.txt");
8995
match response {
9096
Ok(()) if !error_file.exists() => log::info!("Test passed!"),
@@ -173,8 +179,10 @@ fn copy_manifest<R>(test_dir: &Path, env: &mut TestEnvironment<R>) -> anyhow::Re
173179
Ok(())
174180
}
175181

176-
fn test(runtime: &mut Spin) -> TestResult<RuntimeTestFailure> {
177-
let response = runtime.make_http_request(reqwest::Method::GET, "/")?;
182+
fn test(env: &mut TestEnvironment<Spin>) -> TestResult<RuntimeTestFailure> {
183+
let runtime = env.runtime_mut();
184+
let request = testing_framework::Request::new(reqwest::Method::GET, "/");
185+
let response = runtime.make_http_request(request)?;
178186
if response.status() == 200 {
179187
return Ok(());
180188
}

0 commit comments

Comments
 (0)