Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV HOME="/root"
# --------------------------------------
# Need to add the devcontainer workspace folder as a safe directory to enable git
# version control system to be enabled in the containers file system.
RUN git config --global --add safe.directory "/workspaces/plugin-template"
RUN git config --global --add safe.directory "/workspaces/plugin-documentdb"
# --------------------------------------

# --------------------------------------
Expand Down Expand Up @@ -53,7 +53,7 @@ ENV PATH="$PATH:$JAVA_HOME/bin"
# Will load a custom configuration file for Micronaut
ENV MICRONAUT_ENVIRONMENTS=local,override
# Sets the path where you save plugins as Jar and is loaded during the startup process
ENV KESTRA_PLUGINS_PATH="/workspaces/plugin-template/local/plugins"
ENV KESTRA_PLUGINS_PATH="/workspaces/plugin-documentdb/local/plugins"
# --------------------------------------

# --------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "plugin-template",
"name": "plugin-documentdb",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"workspaceFolder": "/workspaces/plugin-template",
"workspaceFolder": "/workspaces/plugin-documentdb",
"forwardPorts": [8080],
"customizations": {
"vscode": {
Expand Down
130 changes: 130 additions & 0 deletions .github/setup-unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash

# Setup script for Kestra DocumentDB Plugin Unit Tests
# This script sets up a local DocumentDB instance for testing both locally and in CI

set -e

echo "🐳 Setting up DocumentDB for unit tests..."

# Check if Docker and Docker Compose are available
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed or not in PATH"
exit 1
fi

# Check for Docker Compose (both v1 and v2)
if ! command -v docker-compose &> /dev/null && ! command -v docker compose &> /dev/null; then
echo "❌ Docker Compose is not installed or not in PATH"
exit 1
fi

# Use docker compose (v2) if available, otherwise fall back to docker-compose (v1)
if command -v docker compose &> /dev/null; then
DC_CMD="docker compose"
COMPOSE_FILE="docker-compose-ci.yml"
else
DC_CMD="docker-compose"
COMPOSE_FILE="docker-compose-ci.yml"
fi

# Stop and remove any existing containers
echo "🧹 Cleaning up existing containers..."
$DC_CMD -f $COMPOSE_FILE down -v --remove-orphans || true

# Start MongoDB and DocumentDB API containers
echo "🚀 Starting MongoDB and DocumentDB API containers..."
$DC_CMD -f $COMPOSE_FILE up -d --build

# Wait for containers to start
echo "⏳ Waiting for containers to start..."
timeout=120
elapsed=0
while ! $DC_CMD -f $COMPOSE_FILE ps | grep -q "mongodb.*Up"; do
if [ $elapsed -ge $timeout ]; then
echo "❌ MongoDB container failed to start within ${timeout} seconds"
$DC_CMD -f $COMPOSE_FILE logs mongodb
exit 1
fi
sleep 5
elapsed=$((elapsed + 5))
echo "⏳ Still waiting for MongoDB container... (${elapsed}/${timeout}s)"
done

echo "✅ MongoDB container is running"

# Wait for DocumentDB API service to be ready
echo "⏳ Waiting for DocumentDB API service to respond..."
timeout=120
elapsed=0
while ! curl -f -s http://localhost:10260/health &> /dev/null; do
if [ $elapsed -ge $timeout ]; then
echo "❌ DocumentDB API service failed to respond within ${timeout} seconds"
echo "API Server logs:"
$DC_CMD -f $COMPOSE_FILE logs documentdb-api
exit 1
fi
sleep 5
elapsed=$((elapsed + 5))
echo "⏳ Still waiting for API service... (${elapsed}/${timeout}s)"
done

echo "✅ DocumentDB API service is ready"

# Create a test database and collection
echo "🗄️ Creating test database and collection..."

# Test database creation by inserting a test document
response=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'testuser:testpass' | base64)" \
-d '{
"database": "test_db",
"collection": "test_collection",
"document": {"_id": "test_doc", "message": "DocumentDB is ready for testing", "timestamp": "'$(date -Iseconds)'"}
}' \
http://localhost:10260/data/v1/action/insertOne)

echo "Insert response: $response"

# Verify we can read from the database
echo "📋 Verifying database connectivity..."
read_response=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'testuser:testpass' | base64)" \
-d '{
"database": "test_db",
"collection": "test_collection",
"filter": {"_id": "test_doc"}
}' \
http://localhost:10260/data/v1/action/find)

echo "Read response: $read_response"

if echo "$read_response" | grep -q "DocumentDB is ready"; then
echo "✅ Test database and collection created successfully"
else
echo "⚠️ Database setup completed, but verification response unclear"
echo "This is normal - tests will handle actual connectivity"
fi

# Show status
echo "📊 Container status:"
$DC_CMD -f $COMPOSE_FILE ps

echo ""
echo "🎉 Setup complete!"
echo ""
echo "📋 Connection details:"
echo " URL: http://localhost:10260"
echo " Username: testuser"
echo " Password: testpass"
echo " Test Database: test_db"
echo " Test Collection: test_collection"
echo ""
echo "🧪 You can now run tests with:"
echo " ./gradlew test"
echo " DOCUMENTDB_INTEGRATION_TESTS=true ./gradlew test"
echo ""
echo "🛑 To stop the services:"
echo " $DC_CMD -f $COMPOSE_FILE down"
Loading
Loading