forked from 3004B-105-TM/code-execution-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·70 lines (53 loc) · 2.1 KB
/
test.sh
File metadata and controls
executable file
·70 lines (53 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Exit on error
set -e
API_URL="http://localhost:8080"
echo "Testing LeetCode Clone Code Execution Service..."
# Test Python code execution
echo "Testing Python code execution..."
PYTHON_RESPONSE=$(curl -s -X POST "$API_URL/execute" \
-H "Content-Type: application/json" \
-d '{"language":"python","code":"print(\"Hello from Python!\")"}')
PYTHON_JOB_ID=$(echo $PYTHON_RESPONSE | sed 's/.*"job_id": "\([^"]*\)".*/\1/')
echo "Python job ID: $PYTHON_JOB_ID"
# Test JavaScript code execution
echo "Testing JavaScript code execution..."
JS_RESPONSE=$(curl -s -X POST "$API_URL/execute" \
-H "Content-Type: application/json" \
-d '{"language":"javascript","code":"console.log(\"Hello from JavaScript!\")"}')
JS_JOB_ID=$(echo $JS_RESPONSE | sed 's/.*"job_id": "\([^"]*\)".*/\1/')
echo "JavaScript job ID: $JS_JOB_ID"
# Test C++ code execution
echo "Testing C++ code execution..."
CPP_RESPONSE=$(curl -s -X POST "$API_URL/execute" \
-H "Content-Type: application/json" \
-d '{"language":"cpp","code":"#include <iostream>\nint main() {\n std::cout << \"Hello from C++!\" << std::endl;\n return 0;\n}"}')
CPP_JOB_ID=$(echo $CPP_RESPONSE | sed 's/.*"job_id": "\([^"]*\)".*/\1/')
echo "C++ job ID: $CPP_JOB_ID"
# Test C# code execution
echo "Testing C# code execution..."
CSHARP_RESPONSE=$(curl -s -X POST "$API_URL/execute" \
-H "Content-Type: application/json" \
-d '{"language":"csharp","code":"using System;\nclass Program {\n static void Main() {\n Console.WriteLine(\"Hello from C#!\");\n }\n}"}')
CSHARP_JOB_ID=$(echo $CSHARP_RESPONSE | sed 's/.*"job_id": "\([^"]*\)".*/\1/')
echo "C# job ID: $CSHARP_JOB_ID"
# Wait for jobs to complete
echo "Waiting for jobs to complete..."
sleep 10
# Check Python result
echo "Checking Python result..."
curl -s "$API_URL/result/$PYTHON_JOB_ID"
echo ""
# Check JavaScript result
echo "Checking JavaScript result..."
curl -s "$API_URL/result/$JS_JOB_ID"
echo ""
# Check C++ result
echo "Checking C++ result..."
curl -s "$API_URL/result/$CPP_JOB_ID"
echo ""
# Check C# result
echo "Checking C# result..."
curl -s "$API_URL/result/$CSHARP_JOB_ID"
echo ""
echo "Test complete!"