Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(spin): add more integration tests #181

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: We chatted about this yesterday, but we could make RUNTIME_CONFIG_PATH an env (defaults to the root) and set an env in the yaml that points to a different location. not blocking, just an option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I remember this discussion. I can work on this in another PR. (nit: I prefer SPIN_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 <[email protected]>"]
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
Loading