Skip to content

Commit

Permalink
test(spin): add more integration tests
Browse files Browse the repository at this point in the history
This commit adds an integration test for spin-keyvalue using dynamic config file that was introduced by deislabs#179 and an integraion test for outbound redis introduced by deislabs#117

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
  • Loading branch information
Mossaka committed Nov 13, 2023
1 parent b2d695c commit d6fcbda
Show file tree
Hide file tree
Showing 20 changed files with 1,436 additions and 520 deletions.
907 changes: 475 additions & 432 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ To build the shims in this project, run `make build`.

To run the integration tests, run `make integration-tests`.

### Cleaning up

To clean up, run `make tests/clean`.

## Example Kubernetes Cluster Deployments
Expand Down
2 changes: 1 addition & 1 deletion containerd-shim-spin/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl SpinEngine {
let mut runtime_config = RuntimeConfig::new(PathBuf::from("/").into());
// Load in runtime config if one exists at expected location
if Path::new(RUNTIME_CONFIG_PATH).exists() {
runtime_config.merge_config_file(RUNTIME_CONFIG_PATH);
runtime_config.merge_config_file(RUNTIME_CONFIG_PATH)?;
}
let mut builder = TriggerExecutorBuilder::new(loader);
builder
Expand Down
28 changes: 19 additions & 9 deletions images/spin-inbound-redis/spin.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
spin_version = "1"
spin_manifest_version = 2

[application]
authors = ["Suneet Nangia <suneetnangia@gmail.com>"]
name = "spin-hello"
trigger = { type = "redis", address = "redis:/localhost:6379" }
name = "spin-inbound-redis"
version = "1.0.0"

[[component]]
environment = { REDIS_ADDRESS = "redis://localhost:6379", REDIS_CHANNEL = "messages-out" }
id = "hello"
[variables]
redis_address = { required = true }
redis_channel = { required = true }

[[trigger.redis]]
address = "redis://redis-service.default.svc.cluster.local:6379"
component = "hello"

[component.hello]
source = "spin_inbound_redis.wasm"
allowed_http_hosts = []
[component.trigger]
channel = "messages-in"
allowed_outbound_hosts = ["redis://*:*"]

[component.hello.variables]
redis_address = "{{ redis_address }}"
redis_channel = "{{ redis_channel }}"

10 changes: 3 additions & 7 deletions images/spin-inbound-redis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ use anyhow::Result;
use bytes::Bytes;
use spin_sdk::redis_component;
use std::str::from_utf8;
use spin_sdk::redis;

const REDIS_ADDRESS_ENV: &str = "REDIS_ADDRESS";
const REDIS_CHANNEL_ENV: &str = "REDIS_CHANNEL";
use spin_sdk::{redis, variables};

/// A simple Spin Redis component.
#[redis_component]
fn on_message(message: Bytes) -> Result<()> {

let address = std::env::var(REDIS_ADDRESS_ENV)?;
let channel = std::env::var(REDIS_CHANNEL_ENV)?;

let address = variables::get("redis_address").expect("could not get variable");
let channel = variables::get("redis_channel").expect("could not get variable");
let conn = redis::Connection::open(&address)?;

println!("{}", from_utf8(&message)?);
Expand Down
Loading

0 comments on commit d6fcbda

Please sign in to comment.