Skip to content

Commit

Permalink
Merge pull request #2154 from fermyon/variables-test
Browse files Browse the repository at this point in the history
Add a runtime test for the variables interface
  • Loading branch information
rylev authored Dec 12, 2023
2 parents ffac141 + 3db6cf7 commit 7397d60
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test-components/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions test-components/variables/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
helper = { path = "../helper" }
8 changes: 8 additions & 0 deletions test-components/variables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Variables

Tests the variable interface.

## Expectations

This test component expects the following to be true:
* Only the variable named "variable" is defined with value "value"
Binary file added test-components/variables/component.wasm
Binary file not shown.
18 changes: 18 additions & 0 deletions test-components/variables/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use helper::ensure_matches;

use bindings::fermyon::spin2_0_0::variables::{get, Error};

helper::define_component!(Component);

impl Component {
fn main() -> Result<(), String> {
ensure_matches!(get("variable"), Ok(val) if val == "value");
ensure_matches!(get("non_existent"), Err(Error::Undefined(_)));

ensure_matches!(get("invalid-name"), Err(Error::InvalidName(_)));
ensure_matches!(get("invalid!name"), Err(Error::InvalidName(_)));
ensure_matches!(get("4invalidname"), Err(Error::InvalidName(_)));

Ok(())
}
}
16 changes: 16 additions & 0 deletions tests/runtime-tests/tests/variables/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
spin_manifest_version = 2

[application]
name = "variables"
authors = ["Fermyon Engineering <[email protected]>"]
version = "0.1.0"

[[trigger.http]]
route = "/"
component = "test"

[component.test]
source = "{{variables}}"

[component.test.variables]
variable = "value"
1 change: 1 addition & 0 deletions tests/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod runtime_tests {
test!(sqlite_no_permission, "sqlite-no-permission");
test!(key_value, "key-value");
test!(key_value_no_permission, "key-value-no-permission");
test!(variables, "variables");

fn run(name: &str) {
let spin_binary_path = env!("CARGO_BIN_EXE_spin").into();
Expand Down

0 comments on commit 7397d60

Please sign in to comment.