-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2141 from fermyon/key-value-runtime-tests
Key/Value runtime tests
- Loading branch information
Showing
20 changed files
with
110 additions
and
748 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = ["sqlite", "helper", "outbound-mysql", "outbound-redis"] | ||
members = ["sqlite", "helper", "outbound-mysql", "outbound-redis", "key-value"] | ||
resolver = "2" |
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 @@ | ||
[package] | ||
name = "key-value" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
helper = { path = "../helper" } |
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 |
Binary file not shown.
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,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(()) | ||
} | ||
} |
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 @@ | ||
Error::AccessDenied |
13 changes: 13 additions & 0 deletions
13
tests/runtime-tests/tests/key-value-no-permission/spin.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,13 @@ | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
name = "key-value" | ||
authors = ["Fermyon Engineering <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "/" | ||
component = "test" | ||
|
||
[component.test] | ||
source = "{{key-value}}" |
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" | ||
authors = ["Fermyon Engineering <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "/" | ||
component = "test" | ||
|
||
[component.test] | ||
source = "{{key-value}}" | ||
key_value_stores = ["default"] |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.