This commit is contained in:
100
runner/test.sh
Executable file
100
runner/test.sh
Executable file
@ -0,0 +1,100 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Simple test script to verify that the runner works properly
|
||||
|
||||
echo "Testing Runner - Dropshell Command Execution Library"
|
||||
echo "=================================================="
|
||||
echo
|
||||
|
||||
# Ensure the binary is built
|
||||
if [ ! -f "build/runner" ]; then
|
||||
echo "Building the project first..."
|
||||
./build.sh
|
||||
fi
|
||||
|
||||
# Run a simple echo command
|
||||
echo "Test 1: Basic command execution"
|
||||
JSON='{"command":"echo","args":["Hello from runner test!"]}'
|
||||
BASE64=$(echo -n "$JSON" | base64)
|
||||
echo "JSON: $JSON"
|
||||
echo "Running command..."
|
||||
build/runner "$BASE64"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Test 1 passed"
|
||||
else
|
||||
echo "❌ Test 1 failed"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
|
||||
# Test with environment variables
|
||||
echo "Test 2: Environment variables"
|
||||
JSON='{"command":"bash","args":["-c","echo Value of TEST_VAR: $TEST_VAR"],"env":{"TEST_VAR":"This is a test environment variable"}}'
|
||||
BASE64=$(echo -n "$JSON" | base64)
|
||||
echo "JSON: $JSON"
|
||||
echo "Running command..."
|
||||
build/runner "$BASE64"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Test 2 passed"
|
||||
else
|
||||
echo "❌ Test 2 failed"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
|
||||
# Test silent mode
|
||||
echo "Test 3: Silent mode"
|
||||
JSON='{"command":"echo","args":["This should not be displayed"],"options":{"silent":true}}'
|
||||
BASE64=$(echo -n "$JSON" | base64)
|
||||
echo "JSON: $JSON"
|
||||
echo "Running command (no output expected)..."
|
||||
OUTPUT=$(build/runner "$BASE64")
|
||||
if [ $? -eq 0 ] && [ -z "$OUTPUT" ]; then
|
||||
echo "✅ Test 3 passed"
|
||||
else
|
||||
echo "❌ Test 3 failed, unexpected output: '$OUTPUT'"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
|
||||
# Test return code handling
|
||||
echo "Test 4: Error return code"
|
||||
JSON='{"command":"false"}'
|
||||
BASE64=$(echo -n "$JSON" | base64)
|
||||
echo "JSON: $JSON"
|
||||
echo "Running command (should fail)..."
|
||||
build/runner "$BASE64" || true
|
||||
RC=$?
|
||||
if [ $RC -ne 0 ]; then
|
||||
echo "✅ Test 4 passed (command correctly reported failure)"
|
||||
else
|
||||
echo "❌ Test 4 failed (command should have returned non-zero)"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
|
||||
# Optional SSH test (disabled by default)
|
||||
# Set ENABLE_SSH_TEST=1 to enable this test
|
||||
if [ "${ENABLE_SSH_TEST}" = "1" ]; then
|
||||
echo "Test 5: SSH to localhost (make sure SSH server is running and you can connect to localhost)"
|
||||
if [ -f "examples/local_ssh.json" ]; then
|
||||
echo "Using examples/local_ssh.json for the test..."
|
||||
./run.sh examples/local_ssh.json || {
|
||||
echo "❌ Test 5 failed"
|
||||
echo "Note: This test requires SSH server running on localhost and proper key-based authentication."
|
||||
echo "Check your SSH configuration or disable this test."
|
||||
exit 1
|
||||
}
|
||||
echo "✅ Test 5 passed"
|
||||
else
|
||||
echo "❌ Test 5 failed: examples/local_ssh.json not found"
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
else
|
||||
echo "Test 5: SSH test disabled (set ENABLE_SSH_TEST=1 to enable)"
|
||||
echo
|
||||
fi
|
||||
|
||||
echo "All tests passed! 🎉"
|
Reference in New Issue
Block a user