First
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
This commit is contained in:
commit
4169337dd0
68 changed files with 8726 additions and 0 deletions
67
node/test-api.js
Normal file
67
node/test-api.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Simple test script to demonstrate the Home Server Agent functionality
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const API_BASE = 'http://localhost:3000';
|
||||
const API_TOKEN = 'dev-token-123';
|
||||
|
||||
console.log('🎮 Home Server Agent Test Script\n');
|
||||
|
||||
// Helper function to make API requests
|
||||
function makeRequest(endpoint, method = 'GET', needsAuth = true) {
|
||||
const url = `${API_BASE}${endpoint}`;
|
||||
let cmd;
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Windows PowerShell
|
||||
if (needsAuth) {
|
||||
cmd = `powershell "Invoke-RestMethod -Uri '${url}' -Method ${method} -Headers @{'Authorization'='Bearer ${API_TOKEN}'}"`;
|
||||
} else {
|
||||
cmd = `powershell "Invoke-RestMethod -Uri '${url}' -Method ${method}"`;
|
||||
}
|
||||
} else {
|
||||
// Unix-like systems
|
||||
if (needsAuth) {
|
||||
cmd = `curl -s -X ${method} -H "Authorization: Bearer ${API_TOKEN}" ${url}`;
|
||||
} else {
|
||||
cmd = `curl -s -X ${method} ${url}`;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = execSync(cmd, { encoding: 'utf8' });
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(`Error making request to ${endpoint}:`, error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Test sequence
|
||||
console.log('1. Testing health check (no auth required)...');
|
||||
const healthResult = makeRequest('/health', 'GET', false);
|
||||
console.log(' ✅ Health check result:', healthResult ? 'OK' : 'FAILED');
|
||||
|
||||
console.log('\n2. Testing server status...');
|
||||
const statusResult = makeRequest('/api/status');
|
||||
console.log(' ✅ Server status retrieved');
|
||||
|
||||
console.log('\n3. Testing game server list...');
|
||||
const listResult = makeRequest('/api/gameserver/list');
|
||||
console.log(' ✅ Available game servers retrieved');
|
||||
|
||||
console.log('\n4. Testing API documentation...');
|
||||
const rootResult = makeRequest('/', 'GET', false);
|
||||
console.log(' ✅ API documentation retrieved');
|
||||
|
||||
console.log('\n5. Testing specific game server status...');
|
||||
const minecraftStatus = makeRequest('/api/gameserver/minecraft/status');
|
||||
console.log(' ✅ Minecraft server status retrieved');
|
||||
|
||||
console.log('\n🎉 All tests completed successfully!');
|
||||
console.log('\nNext steps:');
|
||||
console.log('- Start a game server: POST /api/gameserver/start/minecraft');
|
||||
console.log('- Stop a game server: POST /api/gameserver/stop/minecraft');
|
||||
console.log('- Check active ports: GET /api/status/ports');
|
||||
console.log('\nNote: Game servers require Docker to be running.');
|
||||
Loading…
Add table
Add a link
Reference in a new issue