Skip to content
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
44 changes: 44 additions & 0 deletions .github/workflows/e2e-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: trigger-command E2E Tests
on:
push:
branches: [main]
paths:
- 'crates/trigger-command/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-command.yml'
pull_request:
branches: [main]
paths:
- 'crates/trigger-command/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-command.yml'

jobs:
e2e-test:
name: E2E Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/trigger-command
steps:
- uses: actions/checkout@v6

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.93
targets: wasm32-wasip2

- name: Install Spin
# TODO: bump to v1 once available; see https://github.com/spinframework/actions/issues/20
uses: spinframework/actions/spin/setup@06319d3612303cb558fabe9b13cc0d7256d0aeb9
with:
version: v4.0.0
plugins: pluginify

- name: Run E2E tests
run: ./test/e2e.sh
46 changes: 46 additions & 0 deletions .github/workflows/e2e-mqtt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: trigger-mqtt E2E Tests
on:
push:
branches: [main]
paths:
- 'crates/trigger-mqtt/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-mqtt.yml'
pull_request:
branches: [main]
paths:
- 'crates/trigger-mqtt/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-mqtt.yml'

jobs:
e2e-test:
name: E2E test
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/trigger-mqtt
steps:
- uses: actions/checkout@v6

- name: Install rust target for example app
run: rustup target add wasm32-wasip2

- name: Install Spin
# TODO: bump to v1 once available; see https://github.com/spinframework/actions/issues/20
uses: spinframework/actions/spin/setup@06319d3612303cb558fabe9b13cc0d7256d0aeb9
with:
version: v4.0.0
plugins: pluginify

- name: Install mqttx-cli
run: |
curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.13.0/mqttx-cli-linux-x64
sudo install ./mqttx-cli-linux-x64 /usr/local/bin/mqttx

- name: Run integration test
run: make test
60 changes: 60 additions & 0 deletions .github/workflows/e2e-sqs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: trigger-sqs E2E Tests
on:
push:
branches: [main]
paths:
- 'crates/trigger-sqs/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-sqs.yml'
pull_request:
branches: [main]
paths:
- 'crates/trigger-sqs/**'
- 'Cargo.toml'
- 'Cargo.lock'
- '.github/workflows/e2e-sqs.yml'

jobs:
e2e-test:
name: E2E Test with ElasticMQ
runs-on: ubuntu-latest
defaults:
run:
working-directory: crates/trigger-sqs
steps:
- uses: actions/checkout@v3

- name: Start ElasticMQ
run: make setup-elasticmq

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.93"
targets: wasm32-wasip2

- name: Install Spin
# TODO: bump to v1 once available; see https://github.com/spinframework/actions/issues/20
uses: spinframework/actions/spin/setup@06319d3612303cb558fabe9b13cc0d7256d0aeb9
with:
version: v4.0.0
plugins: pluginify

- name: Run E2E tests
env:
SQS_ENDPOINT: http://localhost:9324
AWS_DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_SESSION_TOKEN: test
run: make test-e2e

- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: spin-logs
path: guest/.spin/logs/*
5 changes: 4 additions & 1 deletion crates/trigger-command/test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="${SCRIPT_DIR}/../../../examples/command-rust-guest-hello"

# Create random temporary directory for logs
LOG_DIR=$(mktemp -d)

Expand All @@ -21,7 +24,7 @@ echo -e "\n${GREEN}Building and installing the command trigger plugin...${NC}"
cargo build --release
spin pluginify --install

spin build --up --from examples/hello-world --quiet --log-dir "$LOG_DIR"
spin build --up --from "${APP_DIR}" --quiet --log-dir "$LOG_DIR"

# Assert that the contents of stdout is `Hello, world!`
OUTPUT=$(cat "$LOG_DIR/hello-world_stdout.txt")
Expand Down
5 changes: 3 additions & 2 deletions crates/trigger-mqtt/tests/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
APP_DIR="${PROJECT_DIR}/../../examples/mqtt-rust-guest"
MQTT_CONTAINER_NAME="emqx-test"
MQTT_HOST="localhost"
MQTT_PORT="1883"
Expand Down Expand Up @@ -132,8 +133,8 @@ start_spin_app() {
SPIN_LOGS_STDOUT="$SPIN_LOG_DIR/mqtt-c01_stdout.txt"

# Build and start the example app in background, capturing output
spin build --from examples/mqtt-app/spin.toml
spin up --from examples/mqtt-app/spin.toml --log-dir "$SPIN_LOG_DIR" &
spin build --from ${APP_DIR}/spin.toml
spin up --from ${APP_DIR}/spin.toml --log-dir "$SPIN_LOG_DIR" &
SPIN_PID=$!

log "Waiting for Spin application to start..."
Expand Down
25 changes: 14 additions & 11 deletions crates/trigger-sqs/e2e-test/e2e-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
Expand All @@ -10,13 +12,14 @@ NC='\033[0m' # No Color
# Configuration
SQS_ENDPOINT="${SQS_ENDPOINT:-http://localhost:9324}"
TEST_QUEUE_NAME="${TEST_QUEUE_NAME:-test-queue}"
SPIN_OUTPUT_LOG="guest/.spin/logs/localtest_stdout.txt"
APP_DIR="${SCRIPT_DIR}/../../../examples/sqs-rust-guest"
SPIN_OUTPUT_LOG="${APP_DIR}/.spin/logs/localtest_stdout.txt"
SPIN_PID=""
MESSAGE="test-value"
MESSAGE_BODY="Test message from e2e test"
ATTRIBUTE_NAME="glonk"

rm -rf guest/.spin
rm -rf ${APP_DIR}/.spin

export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}"

Expand Down Expand Up @@ -71,7 +74,7 @@ echo -e "${GREEN}✓ AWS CLI is available${NC}"
# Check if spin is available
if ! command -v spin &> /dev/null; then
echo -e "${RED}Error: Spin is not installed${NC}"
echo "Please install Spin: https://developer.fermyon.com/spin/install"
echo "Please install Spin: https://spinframework.dev/install"
exit 1
fi
echo -e "${GREEN}✓ Spin is available${NC}"
Expand All @@ -98,34 +101,34 @@ fi

echo -e "${GREEN}✓ Queue created: $QUEUE_URL${NC}"

# Update guest/spin.toml with the queue URL
echo -e "\n${GREEN}Updating guest/spin.toml with queue URL...${NC}"
# Update ${APP_DIR}/spin.toml with the queue URL
echo -e "\n${GREEN}Updating ${APP_DIR}/spin.toml with queue URL...${NC}"

# Backup original spin.toml
cp guest/spin.toml guest/spin.toml.backup
cp ${APP_DIR}/spin.toml ${APP_DIR}/spin.toml.backup

# Replace queue_url
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS sed syntax
sed -i '' "s|queue_url = \".*\"|queue_url = \"$QUEUE_URL\"|g" guest/spin.toml
sed -i '' "s|queue_url = \".*\"|queue_url = \"$QUEUE_URL\"|g" ${APP_DIR}/spin.toml
else
# Linux sed syntax
sed -i "s|queue_url = \".*\"|queue_url = \"$QUEUE_URL\"|g" guest/spin.toml
sed -i "s|queue_url = \".*\"|queue_url = \"$QUEUE_URL\"|g" ${APP_DIR}/spin.toml
fi

echo -e "${GREEN}✓ Updated spin.toml${NC}"

# Build the guest application
echo -e "\n${GREEN}Building guest application...${NC}"
spin build --from guest
spin build --from ${APP_DIR}
echo -e "${GREEN}✓ Guest application built${NC}"

# Start Spin application
echo -e "\n${GREEN}Starting Spin application...${NC}"
AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" \
AWS_ENDPOINT_URL="$SQS_ENDPOINT" \
AWS_ENDPOINT_URL_SQS="$SQS_ENDPOINT" \
spin up --from guest &
spin up --from ${APP_DIR} &
SPIN_PID=$!

echo "Spin started with PID: $SPIN_PID"
Expand Down Expand Up @@ -157,7 +160,7 @@ echo "Waiting for message to be processed..."
sleep 15

# Restore original spin.toml
mv guest/spin.toml.backup guest/spin.toml
mv ${APP_DIR}/spin.toml.backup ${APP_DIR}/spin.toml

# Verify output
echo -e "\n${GREEN}Verifying output...${NC}"
Expand Down
2 changes: 1 addition & 1 deletion examples/mqtt-rust-guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = [ "cdylib" ]
[dependencies]
anyhow = "1"
chrono = "*"
spin-mqtt-sdk = { path = "../../sdk" }
spin-mqtt-sdk = { path = "../../crates/trigger-mqtt/sdk" }


[workspace]
2 changes: 1 addition & 1 deletion examples/sqs-rust-guest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
wit_bindgen::generate!({
world: "spin-sqs",
path: "../sqs3.wit",
path: "../../crates/trigger-sqs/sqs3.wit",
});

use spin::sqs::sqs_types as sqs;
Expand Down
Loading