diff --git a/test-components/Cargo.lock b/test-components/Cargo.lock index 7dc7532ada..2ab07e5266 100644 --- a/test-components/Cargo.lock +++ b/test-components/Cargo.lock @@ -8,145 +8,18 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "async-trait" -version = "0.1.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -[[package]] -name = "bytes" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" - -[[package]] -name = "futures-executor" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" - -[[package]] -name = "futures-macro" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] - -[[package]] -name = "futures-sink" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" - -[[package]] -name = "futures-task" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" - -[[package]] -name = "futures-util" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "hashbrown" version = "0.14.2" @@ -169,17 +42,6 @@ dependencies = [ "wit-bindgen", ] -[[package]] -name = "http" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "id-arena" version = "2.2.1" @@ -215,44 +77,13 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - [[package]] name = "outbound-mysql" version = "0.1.0" dependencies = [ - "anyhow", - "spin-sdk", + "helper", ] -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "proc-macro2" version = "1.0.69" @@ -271,16 +102,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "routefinder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8f99b10dedd317514253dda1fa7c14e344aac96e1f78149a64879ce282aca" -dependencies = [ - "smartcow", - "smartstring", -] - [[package]] name = "ryu" version = "1.0.15" @@ -310,7 +131,7 @@ checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn", ] [[package]] @@ -324,41 +145,12 @@ dependencies = [ "serde", ] -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - [[package]] name = "smallvec" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" -[[package]] -name = "smartcow" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656fcb1c1fca8c4655372134ce87d8afdf5ec5949ebabe8d314be0141d8b5da2" -dependencies = [ - "smartstring", -] - -[[package]] -name = "smartstring" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" -dependencies = [ - "autocfg", - "static_assertions", - "version_check", -] - [[package]] name = "spdx" version = "0.10.2" @@ -368,39 +160,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "spin-macro" -version = "0.1.0" -source = "git+https://github.com/fermyon/spin?branch=main#9e7a68d17f82b51239c4217b57948d8df98db3a0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.1.0-pre0" -source = "git+https://github.com/fermyon/spin?branch=main#9e7a68d17f82b51239c4217b57948d8df98db3a0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - [[package]] name = "sqlite" version = "0.1.0" @@ -408,23 +167,6 @@ dependencies = [ "helper", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.39" @@ -436,26 +178,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "thiserror" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -474,12 +196,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wasm-encoder" version = "0.36.2" @@ -558,7 +274,7 @@ dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.39", + "syn", "wit-bindgen-core", "wit-bindgen-rust", "wit-component", diff --git a/test-components/helper/src/lib.rs b/test-components/helper/src/lib.rs index 3082c9b0c3..191c115061 100644 --- a/test-components/helper/src/lib.rs +++ b/test-components/helper/src/lib.rs @@ -108,7 +108,7 @@ pub fn outgoing_body(body: OutgoingBody, buffer: Vec) -> Result<(), Error> { macro_rules! ensure { ($expr:expr) => {{ if !$expr { - bail!("`{}` unexpectedly returned false", stringify!($expr)) + $crate::bail!("`{}` unexpectedly returned false", stringify!($expr)) } }}; } diff --git a/test-components/outbound-mysql/Cargo.toml b/test-components/outbound-mysql/Cargo.toml index 96ae88c103..9a38d38cd5 100644 --- a/test-components/outbound-mysql/Cargo.toml +++ b/test-components/outbound-mysql/Cargo.toml @@ -7,5 +7,4 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -anyhow = "1.0" -spin-sdk = { git = "https://github.com/fermyon/spin", branch = "main" } +helper = { path = "../helper" } diff --git a/test-components/outbound-mysql/README.md b/test-components/outbound-mysql/README.md index 7a99314962..0d50c6ab8f 100644 --- a/test-components/outbound-mysql/README.md +++ b/test-components/outbound-mysql/README.md @@ -6,3 +6,4 @@ Tests the outbound MySQL interface. This test component expects the following to be true: * It can connect to a MySQL database using the connection string stored in the environment variable `DB_URL` +* It does not have access to a MySQL database at localhost:10000 diff --git a/test-components/outbound-mysql/component.wasm b/test-components/outbound-mysql/component.wasm index 252a4cae97..5e2d2983a5 100755 Binary files a/test-components/outbound-mysql/component.wasm and b/test-components/outbound-mysql/component.wasm differ diff --git a/test-components/outbound-mysql/src/lib.rs b/test-components/outbound-mysql/src/lib.rs index 3ef7c64012..657162c510 100644 --- a/test-components/outbound-mysql/src/lib.rs +++ b/test-components/outbound-mysql/src/lib.rs @@ -1,22 +1,35 @@ -use anyhow::Context; -use spin_sdk::{ - http::{Request, Response}, - http_component, - mysql::{self, Decode}, -}; +use helper::{ensure, ensure_matches, ensure_ok}; +use bindings::fermyon::spin2_0_0::{mysql, rdbms_types}; + +helper::define_component!(Component); const DB_URL_ENV: &str = "DB_URL"; -#[http_component] -fn process(_req: Request) -> anyhow::Result { - let address = std::env::var(DB_URL_ENV)?; - let conn = mysql::Connection::open(&address)?; - test_character_types(&conn)?; - test_numeric_types(&conn)?; - Ok(Response::new(200, vec![])) +impl Component { + fn main() -> Result<(), String> { + ensure_matches!( + mysql::Connection::open("hello"), + Err(mysql::Error::ConnectionFailed(_)) + ); + ensure_matches!( + mysql::Connection::open("localhost:10000"), + Err(mysql::Error::ConnectionFailed(_)) + ); + + let address = ensure_ok!(std::env::var(DB_URL_ENV)); + let conn = ensure_ok!(mysql::Connection::open(&address)); + let rowset = ensure_ok!(test_numeric_types(&conn)); + ensure!(rowset.rows.iter().all(|r| r.len() == 14)); + ensure!(matches!(rowset.rows[0][13], rdbms_types::DbValue::Int8(1))); + + let rowset = ensure_ok!(test_character_types(&conn)); + ensure!(rowset.rows.iter().all(|r| r.len() == 6)); + ensure!(matches!(rowset.rows[0][0], rdbms_types::DbValue::Str(ref s) if s == "rvarchar")); + Ok(()) + } } -fn test_numeric_types(conn: &mysql::Connection) -> anyhow::Result<()> { +fn test_numeric_types(conn: &mysql::Connection) -> Result { let create_table_sql = r#" CREATE TEMPORARY TABLE test_numeric_types ( rtiny TINYINT NOT NULL, @@ -66,29 +79,10 @@ fn test_numeric_types(conn: &mysql::Connection) -> anyhow::Result<()> { FROM test_numeric_types; "#; - let rowset = conn.query(sql, &[])?; - - for row in rowset.rows { - i8::decode(&row[0])?; - i16::decode(&row[1])?; - i32::decode(&row[2])?; - i32::decode(&row[3])?; - i64::decode(&row[4])?; - f32::decode(&row[5])?; - f64::decode(&row[6])?; - u8::decode(&row[7])?; - u16::decode(&row[8])?; - u32::decode(&row[9])?; - u32::decode(&row[10])?; - u64::decode(&row[11])?; - bool::decode(&row[12])?; - bool::decode(&row[13])?; - } - - Ok(()) + conn.query(sql, &[]) } -fn test_character_types(conn: &mysql::Connection) -> anyhow::Result<()> { +fn test_character_types(conn: &mysql::Connection) -> Result { let create_table_sql = r#" CREATE TEMPORARY TABLE test_character_types ( rvarchar varchar(40) NOT NULL, @@ -100,8 +94,7 @@ fn test_character_types(conn: &mysql::Connection) -> anyhow::Result<()> { ); "#; - conn.execute(create_table_sql, &[]) - .context("Error executing MySQL command")?; + conn.execute(create_table_sql, &[])?; let insert_sql = r#" INSERT INTO test_character_types @@ -118,16 +111,5 @@ fn test_character_types(conn: &mysql::Connection) -> anyhow::Result<()> { FROM test_character_types; "#; - let rowset = conn.query(sql, &[])?; - - for row in rowset.rows { - String::decode(&row[0])?; - String::decode(&row[1])?; - String::decode(&row[2])?; - Vec::::decode(&row[3])?; - Vec::::decode(&row[4])?; - Vec::::decode(&row[5])?; - } - - Ok(()) + conn.query(sql, &[]) } diff --git a/tests/runtime-tests/src/lib.rs b/tests/runtime-tests/src/lib.rs index f4184afd21..eb92ff36c9 100644 --- a/tests/runtime-tests/src/lib.rs +++ b/tests/runtime-tests/src/lib.rs @@ -115,6 +115,14 @@ fn run_test(test_path: &Path, mut spin: Spin, on_error: OnTestError) { ) } } + // An empty error message may indicate that the component panicked + ResponseKind::Err(e) if e.is_empty() => { + let e = spin + .stderr + .output_as_str() + .unwrap_or("Spin server did not return body and did not write to stderr"); + error!(on_error, "Test '{}' errored: {e}", test_path.display()); + } ResponseKind::Err(e) => { error!(on_error, "Test '{}' errored: {e}", test_path.display()); }