-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-api-integration.js
More file actions
73 lines (60 loc) · 2.03 KB
/
Copy pathtest-api-integration.js
File metadata and controls
73 lines (60 loc) · 2.03 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
71
72
73
#!/usr/bin/env node
/**
* Test script to validate frontend API integration with new backend
*/
const API_BASE = 'http://localhost:8080/v1';
async function testAPI() {
console.log('🧪 Testing API Integration with NQRust-MicroVM Backend\n');
const tests = [
{ name: 'List VMs', endpoint: '/vms' },
{ name: 'List Templates', endpoint: '/templates' },
{ name: 'List Images', endpoint: '/images' },
];
for (const test of tests) {
try {
console.log(`⏳ Testing: ${test.name}`);
const response = await fetch(API_BASE + test.endpoint);
if (!response.ok) {
console.log(`❌ ${test.name}: HTTP ${response.status}`);
continue;
}
const data = await response.json();
console.log(`✅ ${test.name}: ${data.items ? data.items.length : 0} items`);
if (data.items && data.items.length > 0) {
console.log(` Sample item keys: ${Object.keys(data.items[0]).join(', ')}`);
}
} catch (error) {
console.log(`❌ ${test.name}: ${error.message}`);
}
}
// Test creating a template
console.log('\n⏳ Testing: Create Template');
try {
const templateData = {
name: 'test-template-' + Date.now(),
spec: {
vcpu: 1,
mem_mib: 256,
kernel_path: '/path/to/kernel',
rootfs_path: '/path/to/rootfs'
}
};
const response = await fetch(API_BASE + '/templates', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(templateData)
});
if (response.ok) {
const result = await response.json();
console.log(`✅ Create Template: Created with ID ${result.id}`);
// Clean up - delete the template
await fetch(API_BASE + `/templates/${result.id}`, { method: 'DELETE' }).catch(() => {});
} else {
console.log(`❌ Create Template: HTTP ${response.status}`);
}
} catch (error) {
console.log(`❌ Create Template: ${error.message}`);
}
console.log('\n🎉 API Integration test complete!');
}
testAPI().catch(console.error);