-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
- Loading branch information
Showing
7 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
name = "key-value-wasi" | ||
authors = ["Fermyon Engineering <engineering@fermyon.com>"] | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "/" | ||
component = "test" | ||
|
||
[component.test] | ||
source = "%{source=key-value-wasi}" | ||
key_value_stores = ["default"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
tests/test-components/components/key-value-wasi/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "key-value-wasi" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
helper = { path = "../../helper" } | ||
wit-bindgen = "0.16.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
51 changes: 51 additions & 0 deletions
51
tests/test-components/components/key-value-wasi/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use helper::{ensure_matches, ensure_ok}; | ||
|
||
use bindings::wasi::keyvalue::store::{Error, open, KeyResponse}; | ||
|
||
helper::define_component!(Component); | ||
|
||
impl Component { | ||
fn main() -> Result<(), String> { | ||
|
||
ensure_matches!(open("forbidden"), Err(Error::AccessDenied)); | ||
|
||
let store = ensure_ok!(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!(keys(&store.list_keys(None)), 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(v)) if v == b"baz"); | ||
ensure_matches!(keys(&store.list_keys(None)), Ok([bar]) if bar == "bar"); | ||
ensure_matches!(keys(&store.list_keys(Some(0))), Ok([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!(keys(&store.list_keys(None)), Ok([bar]) if bar == "bar"); | ||
|
||
// Set another key | ||
ensure_ok!(store.set("qux", b"yay")); | ||
ensure_matches!(keys(&store.list_keys(None)), 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!(keys(&store.list_keys(None)), Ok(&[])); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
fn keys<E>(res: &Result<KeyResponse, E>) -> Result<&[String], &E> { | ||
res.as_ref().map(|kr| kr.keys.as_slice()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters