Skip to content

Commit 7397d60

Browse files
authored
Merge pull request #2154 from fermyon/variables-test
Add a runtime test for the variables interface
2 parents ffac141 + 3db6cf7 commit 7397d60

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

test-components/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-components/variables/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "variables"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
helper = { path = "../helper" }

test-components/variables/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Variables
2+
3+
Tests the variable interface.
4+
5+
## Expectations
6+
7+
This test component expects the following to be true:
8+
* Only the variable named "variable" is defined with value "value"
132 KB
Binary file not shown.

test-components/variables/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use helper::ensure_matches;
2+
3+
use bindings::fermyon::spin2_0_0::variables::{get, Error};
4+
5+
helper::define_component!(Component);
6+
7+
impl Component {
8+
fn main() -> Result<(), String> {
9+
ensure_matches!(get("variable"), Ok(val) if val == "value");
10+
ensure_matches!(get("non_existent"), Err(Error::Undefined(_)));
11+
12+
ensure_matches!(get("invalid-name"), Err(Error::InvalidName(_)));
13+
ensure_matches!(get("invalid!name"), Err(Error::InvalidName(_)));
14+
ensure_matches!(get("4invalidname"), Err(Error::InvalidName(_)));
15+
16+
Ok(())
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
spin_manifest_version = 2
2+
3+
[application]
4+
name = "variables"
5+
authors = ["Fermyon Engineering <[email protected]>"]
6+
version = "0.1.0"
7+
8+
[[trigger.http]]
9+
route = "/"
10+
component = "test"
11+
12+
[component.test]
13+
source = "{{variables}}"
14+
15+
[component.test.variables]
16+
variable = "value"

tests/runtime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod runtime_tests {
2727
test!(sqlite_no_permission, "sqlite-no-permission");
2828
test!(key_value, "key-value");
2929
test!(key_value_no_permission, "key-value-no-permission");
30+
test!(variables, "variables");
3031

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

0 commit comments

Comments
 (0)