|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Integration test script for gofetch MCP server |
| 4 | +# Tests SSE and streamable-http transports using client binary |
| 5 | +set -e |
| 6 | + |
| 7 | +echo "Running integration tests for gofetch MCP server..." |
| 8 | + |
| 9 | +# Test 1: Build the image using task build-image |
| 10 | +echo "🏗️ Building Docker image using task build-image..." |
| 11 | +task build-image |
| 12 | +if [ $? -eq 0 ]; then |
| 13 | + echo "✓ Docker image built successfully using task build-image" |
| 14 | +else |
| 15 | + echo "✗ Failed to build Docker image using task build-image" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +IMAGE_NAME="ghcr.io/stackloklabs/gofetch/server:latest" |
| 20 | + |
| 21 | +cleanup() { |
| 22 | + docker rm -f gofetch-sse-endpoints-test > /dev/null 2>&1 || true |
| 23 | + docker rm -f gofetch-http-endpoints-test > /dev/null 2>&1 || true |
| 24 | +} |
| 25 | +trap cleanup EXIT |
| 26 | + |
| 27 | +check_status() { |
| 28 | + local method=$1 |
| 29 | + local url=$2 |
| 30 | + local data=$3 |
| 31 | + local header=$4 |
| 32 | + |
| 33 | + if [ "$method" = "GET" ]; then |
| 34 | + curl -s -o /dev/null -m 5 -w "%{http_code}" ${header} "$url" |
| 35 | + else |
| 36 | + curl -s -o /dev/null -m 5 -w "%{http_code}" -X POST -H 'Content-Type: application/json' ${header} -d "${data}" "$url" |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +############################################################### |
| 41 | +# SSE transport endpoint checks |
| 42 | +############################################################### |
| 43 | +echo "" |
| 44 | +echo "🌊 ========== SSE ENDPOINT CHECKS ==========" |
| 45 | +docker run --rm -d --name gofetch-sse-endpoints-test -p 8080:8080 "$IMAGE_NAME" --transport sse --port 8080 > /dev/null 2>&1 |
| 46 | + |
| 47 | +if docker ps | grep -q gofetch-sse-endpoints-test; then |
| 48 | + echo "✓ SSE container started on port 8080" |
| 49 | +else |
| 50 | + echo "✗ Failed to start SSE container" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +echo "🔎 Checking /sse (GET)" |
| 55 | +# For SSE, the connection stays open; curl may timeout with exit 28. Capture headers and validate. |
| 56 | +SSE_HEADERS=$(curl -sS -m 5 -D - -o /dev/null -H 'Accept: text/event-stream' http://localhost:8080/sse || true) |
| 57 | +if echo "$SSE_HEADERS" | grep -qiE '^HTTP/[^ ]+ 200' && echo "$SSE_HEADERS" | grep -qi 'content-type: *text/event-stream'; then |
| 58 | + echo "✓ /sse endpoint reachable (200, text/event-stream)" |
| 59 | +else |
| 60 | + echo "! /sse endpoint did not return expected headers" |
| 61 | + echo "$SSE_HEADERS" | sed 's/^/H: /' |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +echo "🔎 Checking /messages (POST)" |
| 66 | +MSG_STATUS=$(check_status POST "http://localhost:8080/messages" '{}' "" || true) |
| 67 | +if [ "$MSG_STATUS" = "200" ] || [ "$MSG_STATUS" = "204" ] || [ "$MSG_STATUS" = "400" ]; then |
| 68 | + echo "✓ /messages endpoint reachable ($MSG_STATUS)" |
| 69 | +else |
| 70 | + echo "! /messages endpoint not reachable (status: $MSG_STATUS)" |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | +docker rm -f gofetch-sse-endpoints-test > /dev/null 2>&1 || true |
| 75 | +echo "✓ SSE container shut down" |
| 76 | + |
| 77 | +############################################################### |
| 78 | +# Streamable HTTP transport endpoint checks |
| 79 | +############################################################### |
| 80 | +echo "" |
| 81 | +echo "🌐 ========== STREAMABLE-HTTP ENDPOINT CHECKS ==========" |
| 82 | +docker run --rm -d --name gofetch-http-endpoints-test -p 8081:8081 "$IMAGE_NAME" --transport streamable-http --port 8081 > /dev/null 2>&1 |
| 83 | + |
| 84 | +if docker ps | grep -q gofetch-http-endpoints-test; then |
| 85 | + echo "✓ Streamable HTTP container started on port 8081" |
| 86 | +else |
| 87 | + echo "✗ Failed to start Streamable HTTP container" |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +echo "🔎 Checking /mcp (GET)" |
| 92 | +MCP_GET_STATUS=$(check_status GET "http://localhost:8081/mcp" "" "" || true) |
| 93 | +if [ "$MCP_GET_STATUS" = "200" ] || [ "$MCP_GET_STATUS" = "400" ]; then |
| 94 | + echo "✓ /mcp endpoint reachable via GET ($MCP_GET_STATUS)" |
| 95 | +else |
| 96 | + echo "! /mcp endpoint GET not reachable (status: $MCP_GET_STATUS)" |
| 97 | + exit 1 |
| 98 | +fi |
| 99 | + |
| 100 | +echo "🔎 Checking /mcp (POST)" |
| 101 | +MCP_POST_STATUS=$(check_status POST "http://localhost:8081/mcp" '{}' "" || true) |
| 102 | +if [ "$MCP_POST_STATUS" = "200" ] || [ "$MCP_POST_STATUS" = "204" ] || [ "$MCP_POST_STATUS" = "400" ]; then |
| 103 | + echo "✓ /mcp endpoint reachable via POST ($MCP_POST_STATUS)" |
| 104 | +else |
| 105 | + echo "! /mcp endpoint POST not reachable (status: $MCP_POST_STATUS)" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | + |
| 109 | +docker rm -f gofetch-http-endpoints-test > /dev/null 2>&1 || true |
| 110 | +echo "✓ Streamable HTTP container shut down" |
| 111 | + |
| 112 | +echo "✅ Endpoint integration tests passed" |
| 113 | + |
| 114 | + |
0 commit comments