Skip to content

Commit b77d25d

Browse files
committed
Tests and contexting some file-not-found errors
Signed-off-by: itowlson <[email protected]>
1 parent 8847533 commit b77d25d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4462
-15
lines changed

crates/build/src/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,56 @@ mod tests {
246246
.await
247247
.unwrap();
248248
}
249+
250+
#[tokio::test]
251+
async fn succeeds_if_target_env_matches() {
252+
let manifest_path = test_data_root().join("good_target_env.toml");
253+
build(&manifest_path, &[], TargetChecking::Check, None)
254+
.await
255+
.unwrap();
256+
}
257+
258+
#[tokio::test]
259+
async fn fails_if_target_env_does_not_match() {
260+
let manifest_path = test_data_root().join("bad_target_env.toml");
261+
let err = build(&manifest_path, &[], TargetChecking::Check, None)
262+
.await
263+
.expect_err("should have failed")
264+
.to_string();
265+
266+
// build prints validation errors rather than returning them to top level
267+
// (because there could be multiple errors) - see has_meaningful_error_if_target_env_does_not_match
268+
assert!(
269+
err.contains("one or more was incompatible with one or more of the deployment targets")
270+
);
271+
}
272+
273+
#[tokio::test]
274+
async fn has_meaningful_error_if_target_env_does_not_match() {
275+
let manifest_file = test_data_root().join("bad_target_env.toml");
276+
let manifest = spin_manifest::manifest_from_file(&manifest_file).unwrap();
277+
let application = spin_environments::ApplicationToValidate::new(
278+
manifest.clone(),
279+
manifest_file.parent().unwrap(),
280+
)
281+
.await
282+
.context("unable to load application for checking against deployment targets")
283+
.unwrap();
284+
285+
let target_validation = spin_environments::validate_application_against_environment_ids(
286+
&application,
287+
&manifest.application.targets,
288+
None,
289+
manifest_file.parent().unwrap(),
290+
)
291+
.await
292+
.context("unable to check if the application is compatible with deployment targets")
293+
.unwrap();
294+
295+
assert_eq!(1, target_validation.errors().len());
296+
297+
let err = target_validation.errors()[0].to_string();
298+
299+
assert!(err.contains("world wasi:cli/[email protected] does not provide an import named"));
300+
}
249301
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "bad"
5+
targets = [{ path = "env/wasi-minimal.toml" }]
6+
7+
[[trigger.command]]
8+
component = { source = "test-components/test-command.wasm" }

crates/build/tests/env/wasi-all.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[triggers]
2+
command = { worlds = [{ path = "../wit/cmd-full", world = "wasi:cli/[email protected]"}] }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[triggers]
2+
command = { worlds = [{ path = "../wit/cmd-minimal", world = "wasi:cli/[email protected]"}] }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "good"
5+
targets = [{ path = "env/wasi-all.toml" }]
6+
7+
[[trigger.command]]
8+
component = { source = "test-components/test-command.wasm" }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Recreating the test components
2+
3+
```
4+
cd source/test-command
5+
cargo build --release --target wasm32-wasip1
6+
```
7+
8+
then copy from `target/wasm32-wasip1/release/` to this directory.
9+
10+
**IMPORTANT:** Do not use the `wasm32-wasip2` target. It generates to the 0.2.x world (0.2.3 at time of writing), and Component Model tooling does not yet accept that as compatible with the 0.2.0 world.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "test-command"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
8+
[workspace]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package wasi:cli@0.2.0;
2+
3+
world command {
4+
include imports;
5+
6+
export run;
7+
}

0 commit comments

Comments
 (0)