diff --git a/test-components/Cargo.lock b/test-components/Cargo.lock index 587c1fc92..e7f84c0dd 100644 --- a/test-components/Cargo.lock +++ b/test-components/Cargo.lock @@ -65,6 +65,13 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "key-value" +version = "0.1.0" +dependencies = [ + "helper", +] + [[package]] name = "leb128" version = "0.2.5" diff --git a/test-components/Cargo.toml b/test-components/Cargo.toml index ab480fa65..a091d0918 100644 --- a/test-components/Cargo.toml +++ b/test-components/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["sqlite", "helper", "outbound-mysql", "outbound-redis"] +members = ["sqlite", "helper", "outbound-mysql", "outbound-redis", "key-value"] resolver = "2" diff --git a/test-components/key-value/Cargo.toml b/test-components/key-value/Cargo.toml new file mode 100644 index 000000000..b11b6dc14 --- /dev/null +++ b/test-components/key-value/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "key-value" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +helper = { path = "../helper" } diff --git a/test-components/key-value/README.md b/test-components/key-value/README.md new file mode 100644 index 000000000..2cff70108 --- /dev/null +++ b/test-components/key-value/README.md @@ -0,0 +1,10 @@ +# Key Value + +Tests the key/value interface. + +## Expectations + +This test component expects the following to be true: +* It is given permission to open a connection to the "default" store. +* It does not have permission to access a store named "forbidden". +* It is empty diff --git a/test-components/key-value/component.wasm b/test-components/key-value/component.wasm new file mode 100755 index 000000000..3d5576c5d Binary files /dev/null and b/test-components/key-value/component.wasm differ diff --git a/test-components/key-value/src/lib.rs b/test-components/key-value/src/lib.rs new file mode 100644 index 000000000..e431ee725 --- /dev/null +++ b/test-components/key-value/src/lib.rs @@ -0,0 +1,45 @@ +use helper::{ensure_matches, ensure_ok}; + +use bindings::fermyon::spin2_0_0::key_value::{Error, Store}; + +helper::define_component!(Component); + +impl Component { + fn main() -> Result<(), String> { + ensure_matches!(Store::open("forbidden"), Err(Error::AccessDenied)); + + let store = ensure_ok!(Store::open("default")); + + // Ensure nothing set in `bar` key + ensure_ok!(store.delete("bar")); + ensure_matches!(store.exists("bar"), Ok(false)); + ensure_matches!(store.get("bar"), Ok(None)); + ensure_matches!(store.get_keys().as_deref(), Ok(&[])); + + // Set `bar` key + ensure_ok!(store.set("bar", b"baz")); + ensure_matches!(store.exists("bar"), Ok(true)); + ensure_matches!(store.get("bar"), Ok(Some(baz)) if baz == b"baz"); + ensure_matches!(store.get_keys().as_deref(), Ok(&[ref bar]) if bar == "bar"); + + // Override `bar` key + ensure_ok!(store.set("bar", b"wow")); + ensure_matches!(store.exists("bar"), Ok(true)); + ensure_matches!(store.get("bar"), Ok(Some(wow)) if wow == b"wow"); + ensure_matches!(store.get_keys().as_deref(), Ok(&[ref bar]) if bar == "bar"); + + // Set another key + ensure_ok!(store.set("qux", b"yay")); + ensure_matches!(store.get_keys().as_deref(), Ok(c) if c.len() == 2 && c.contains(&"bar".into()) && c.contains(&"qux".into())); + + // Delete everything + ensure_ok!(store.delete("bar")); + ensure_ok!(store.delete("bar")); + ensure_ok!(store.delete("qux")); + ensure_matches!(store.exists("bar"), Ok(false)); + ensure_matches!(store.get("qux"), Ok(None)); + ensure_matches!(store.get_keys().as_deref(), Ok(&[])); + + Ok(()) + } +} diff --git a/tests/runtime-tests/tests/key-value-no-permission/error.txt b/tests/runtime-tests/tests/key-value-no-permission/error.txt new file mode 100644 index 000000000..11a87ef97 --- /dev/null +++ b/tests/runtime-tests/tests/key-value-no-permission/error.txt @@ -0,0 +1 @@ +Error::AccessDenied \ No newline at end of file diff --git a/tests/runtime-tests/tests/key-value-no-permission/spin.toml b/tests/runtime-tests/tests/key-value-no-permission/spin.toml new file mode 100644 index 000000000..9410446a4 --- /dev/null +++ b/tests/runtime-tests/tests/key-value-no-permission/spin.toml @@ -0,0 +1,13 @@ +spin_manifest_version = 2 + +[application] +name = "key-value" +authors = ["Fermyon Engineering "] +version = "0.1.0" + +[[trigger.http]] +route = "/" +component = "test" + +[component.test] +source = "{{key-value}}" diff --git a/tests/runtime-tests/tests/key-value/spin.toml b/tests/runtime-tests/tests/key-value/spin.toml new file mode 100644 index 000000000..5161be2d5 --- /dev/null +++ b/tests/runtime-tests/tests/key-value/spin.toml @@ -0,0 +1,14 @@ +spin_manifest_version = 2 + +[application] +name = "key-value" +authors = ["Fermyon Engineering "] +version = "0.1.0" + +[[trigger.http]] +route = "/" +component = "test" + +[component.test] +source = "{{key-value}}" +key_value_stores = ["default"] diff --git a/tests/runtime.rs b/tests/runtime.rs index 175dba12a..1d9513382 100644 --- a/tests/runtime.rs +++ b/tests/runtime.rs @@ -20,6 +20,8 @@ mod runtime_tests { test!(outbound_redis_no_permission, "outbound-redis-no-permission"); test!(sqlite, "sqlite"); test!(sqlite_no_permission, "sqlite-no-permission"); + test!(key_value, "key-value"); + test!(key_value_no_permission, "key-value-no-permission"); fn run(name: &str) { let spin_binary_path = env!("CARGO_BIN_EXE_spin").into(); diff --git a/tests/spinup_tests.rs b/tests/spinup_tests.rs index 95c321e34..0bbcee6b9 100644 --- a/tests/spinup_tests.rs +++ b/tests/spinup_tests.rs @@ -22,11 +22,6 @@ mod spinup_tests { testcases::key_value_works(CONTROLLER).await } - #[tokio::test] - async fn key_value_validation_works() { - testcases::key_value_validation_works(CONTROLLER).await - } - #[tokio::test] async fn http_go_works() { testcases::http_go_works(CONTROLLER).await diff --git a/tests/testcases/key-value-undefined-store/.cargo/config.toml b/tests/testcases/key-value-undefined-store/.cargo/config.toml deleted file mode 100644 index 6b77899cb..000000000 --- a/tests/testcases/key-value-undefined-store/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-wasi" diff --git a/tests/testcases/key-value-undefined-store/Cargo.lock b/tests/testcases/key-value-undefined-store/Cargo.lock deleted file mode 100644 index d088634dc..000000000 --- a/tests/testcases/key-value-undefined-store/Cargo.lock +++ /dev/null @@ -1,616 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -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.38", -] - -[[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 = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[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.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -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.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "id-arena" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" - -[[package]] -name = "indexmap" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" -dependencies = [ - "equivalent", - "hashbrown", - "serde", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "key-value-undefined-store" -version = "0.1.0" -dependencies = [ - "anyhow", - "bytes", - "http", - "itertools", - "serde", - "serde_qs", - "spin-sdk", -] - -[[package]] -name = "leb128" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" - -[[package]] -name = "log" -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 = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_qs" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0431a35568651e363364210c91983c1da5eb29404d9f0928b67d4ebcfa7d330c" -dependencies = [ - "percent-encoding", - "serde", - "thiserror", -] - -[[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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b32ed6d899ab23174302ff105c1577e45a06b08d4fe0a9dd13ce804bbbf71" -dependencies = [ - "smallvec", -] - -[[package]] -name = "spin-macro" -version = "0.1.0" -dependencies = [ - "anyhow", - "bytes", - "http", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "spin-sdk" -version = "2.1.0-pre0" -dependencies = [ - "anyhow", - "async-trait", - "bytes", - "form_urlencoded", - "futures", - "http", - "once_cell", - "routefinder", - "serde", - "serde_json", - "spin-macro", - "thiserror", - "wit-bindgen", -] - -[[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.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-xid" -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.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca90ba1b5b0a70d3d49473c5579951f3bddc78d47b59256d2f9d4922b150aca" -dependencies = [ - "leb128", -] - -[[package]] -name = "wasm-metadata" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14abc161bfda5b519aa229758b68f2a52b45a12b993808665c857d1a9a00223c" -dependencies = [ - "anyhow", - "indexmap", - "serde", - "serde_derive", - "serde_json", - "spdx", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.115.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e06c0641a4add879ba71ccb3a1e4278fd546f76f1eafb21d8f7b07733b547cd5" -dependencies = [ - "indexmap", - "semver", -] - -[[package]] -name = "wit-bindgen" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d92ce0ca6b6074059413a9581a637550c3a740581c854f9847ec293c8aed71" -dependencies = [ - "bitflags", - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565b945ae074886071eccf9cdaf8ccd7b959c2b0d624095bea5fe62003e8b3e0" -dependencies = [ - "anyhow", - "wit-component", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5695ff4e41873ed9ce56d2787e6b5772bdad9e70e2c1d2d160621d1762257f4f" -dependencies = [ - "anyhow", - "heck", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91835ea4231da1fe7971679d505ba14be7826e192b6357f08465866ef482e08" -dependencies = [ - "anyhow", - "proc-macro2", - "quote", - "syn 2.0.38", - "wit-bindgen-core", - "wit-bindgen-rust", - "wit-component", -] - -[[package]] -name = "wit-component" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87488b57a08e2cbbd076b325acbe7f8666965af174d69d5929cd373bd54547f" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ace9943d89bbf3dbbc71b966da0e7302057b311f36a4ac3d65ddfef17b52cf" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", -] diff --git a/tests/testcases/key-value-undefined-store/Cargo.toml b/tests/testcases/key-value-undefined-store/Cargo.toml deleted file mode 100644 index 7ad16f16a..000000000 --- a/tests/testcases/key-value-undefined-store/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "key-value-undefined-store" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = [ "cdylib" ] - -[dependencies] -# Useful crate to handle errors. -anyhow = "1" -# Crate to simplify working with bytes. -bytes = "1" -# General-purpose crate with common HTTP types. -http = "0.2" -itertools = "0.10" -serde = { version = "1.0", features = ["derive"] } -serde_qs = "0.12" -spin-sdk = { path = "../../../sdk/rust"} - -[workspace] \ No newline at end of file diff --git a/tests/testcases/key-value-undefined-store/spin.toml b/tests/testcases/key-value-undefined-store/spin.toml deleted file mode 100644 index ab18a976c..000000000 --- a/tests/testcases/key-value-undefined-store/spin.toml +++ /dev/null @@ -1,16 +0,0 @@ -spin_version = "1" -authors = ["Fermyon Engineering "] -description = "A simple application that requests access to an undefined key/value store." -name = "key-value" -trigger = {type = "http", base = "/test"} -version = "1.0.0" - -[[component]] -id = "hello" -# intentionally use undefined ~words~ stores -key_value_stores = ["default", "anaspeptic", "pericombobulations"] -source = "target/wasm32-wasi/release/key_value_undefined_store.wasm" -[component.trigger] -route = "/..." -[component.build] -command = "cargo build --release --target wasm32-wasi" diff --git a/tests/testcases/key-value-undefined-store/src/lib.rs b/tests/testcases/key-value-undefined-store/src/lib.rs deleted file mode 100644 index e1a6c3b8f..000000000 --- a/tests/testcases/key-value-undefined-store/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -use anyhow::Result; -use spin_sdk::http_component; - -#[http_component] -fn handle_request(_req: http::Request<()>) -> Result> { - // We don't need to do anything here: it should never get called because - // spin up should fail at K/V validation. - Ok(http::Response::builder().status(200).body(())?) -} diff --git a/tests/testcases/key-value/Cargo.lock b/tests/testcases/key-value/Cargo.lock index c67b7bc73..507850f7a 100644 --- a/tests/testcases/key-value/Cargo.lock +++ b/tests/testcases/key-value/Cargo.lock @@ -216,7 +216,6 @@ name = "key-value" version = "0.1.0" dependencies = [ "anyhow", - "bytes", "http", "itertools", "serde", diff --git a/tests/testcases/key-value/Cargo.toml b/tests/testcases/key-value/Cargo.toml index abc0dafe1..7a19ff72e 100644 --- a/tests/testcases/key-value/Cargo.toml +++ b/tests/testcases/key-value/Cargo.toml @@ -1,21 +1,17 @@ [package] -name = "key-value" +name = "key-value" version = "0.1.0" edition = "2021" [lib] -crate-type = [ "cdylib" ] +crate-type = ["cdylib"] [dependencies] -# Useful crate to handle errors. anyhow = "1" -# Crate to simplify working with bytes. -bytes = "1" -# General-purpose crate with common HTTP types. http = "0.2" itertools = "0.10" serde = { version = "1.0", features = ["derive"] } serde_qs = "0.12" -spin-sdk = { path = "../../../sdk/rust"} +spin-sdk = { path = "../../../sdk/rust" } -[workspace] \ No newline at end of file +[workspace] diff --git a/tests/testcases/key-value/src/lib.rs b/tests/testcases/key-value/src/lib.rs index 8d4a4ff56..c534c8937 100644 --- a/tests/testcases/key-value/src/lib.rs +++ b/tests/testcases/key-value/src/lib.rs @@ -1,16 +1,9 @@ use anyhow::{ensure, Result}; use itertools::sorted; -use spin_sdk::{ - http_component, - key_value::{Error, Store}, -}; +use spin_sdk::{http_component, key_value::Store}; #[http_component] fn handle_request(req: http::Request<()>) -> Result> { - // TODO: once we allow users to pass non-default stores, test that opening - // an allowed-but-non-existent one returns Error::NoSuchStore - ensure!(matches!(Store::open("forbidden"), Err(Error::AccessDenied))); - let query = req .uri() .query() @@ -25,22 +18,6 @@ fn handle_request(req: http::Request<()>) -> Result> { let store = Store::open_default()?; - store.delete("bar")?; - - ensure!(!store.exists("bar")?); - - ensure!(matches!(store.get("bar"), Ok(None))); - - store.set("bar", b"baz")?; - - ensure!(store.exists("bar")?); - - ensure!(Some(b"baz" as &[_]) == store.get("bar")?.as_deref()); - - store.set("bar", b"wow")?; - - ensure!(Some(b"wow" as &[_]) == store.get("bar")?.as_deref()); - let result = store.get(init_key)?; ensure!( Some(init_val.as_bytes()) == result.as_deref(), @@ -49,21 +26,16 @@ fn handle_request(req: http::Request<()>) -> Result> { ); ensure!( - sorted(vec!["bar".to_owned(), init_key.to_owned()]).collect::>() + sorted(vec![init_key.to_owned()]).collect::>() == sorted(store.get_keys()?).collect::>(), - "Expected exectly keys 'bar' and '{}' but got '{:?}'", + "Expected exactly keys '{}' but got '{:?}'", init_key, &store.get_keys()? ); - store.delete("bar")?; store.delete(init_key)?; ensure!(&[] as &[String] == &store.get_keys()?); - ensure!(!store.exists("bar")?); - - ensure!(matches!(store.get("bar"), Ok(None))); - Ok(http::Response::builder().status(200).body(())?) } diff --git a/tests/testcases/mod.rs b/tests/testcases/mod.rs index 84b19b736..a247d0403 100644 --- a/tests/testcases/mod.rs +++ b/tests/testcases/mod.rs @@ -155,44 +155,6 @@ pub async fn key_value_works(controller: &dyn Controller) { tc.run(controller).await.unwrap() } -pub async fn key_value_validation_works(controller: &dyn Controller) { - async fn checks( - _: AppMetadata, - _: Option>>, - stderr: Option>>, - ) -> Result<()> { - let err_text = utils::get_output(stderr).await.unwrap(); - let expected1 = "Component hello uses store 'anaspeptic'"; - let expected2 = "Component hello uses store 'pericombobulations'"; - - assert!( - err_text.contains(expected1), - "Expected error containing '{expected1}' but got '{err_text}'" - ); - assert!( - err_text.contains(expected2), - "Expected error containing '{expected2}' but got '{err_text}'" - ); - Ok(()) - } - - let tc = TestCaseBuilder::default() - .name("key-value-undefined-store".to_string()) - .appname(Some("key-value-undefined-store".to_string())) - .template(None) - .assertions( - |metadata: AppMetadata, - stdout_stream: Option>>, - stderr_stream: Option>>| { - Box::pin(checks(metadata, stdout_stream, stderr_stream)) - }, - ) - .build() - .unwrap(); - - tc.try_run(controller).await.unwrap(); -} - pub async fn http_python_works(controller: &dyn Controller) { async fn checks( metadata: AppMetadata,