230 líneas
5.9 KiB
Bash
Archivo Ejecutable
230 líneas
5.9 KiB
Bash
Archivo Ejecutable
#!/bin/bash
|
|
|
|
##############################################################################
|
|
# EasyQEMU Test Suite
|
|
# Run basic tests to ensure everything works correctly
|
|
##############################################################################
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
PASSED=0
|
|
FAILED=0
|
|
TESTS=0
|
|
|
|
test_start() {
|
|
TESTS=$((TESTS + 1))
|
|
echo -ne "${BLUE}[TEST $TESTS]${NC} $1... "
|
|
}
|
|
|
|
test_pass() {
|
|
PASSED=$((PASSED + 1))
|
|
echo -e "${GREEN}PASSED${NC}"
|
|
}
|
|
|
|
test_fail() {
|
|
FAILED=$((FAILED + 1))
|
|
echo -e "${RED}FAILED${NC}"
|
|
if [[ -n "$1" ]]; then
|
|
echo " Error: $1"
|
|
fi
|
|
}
|
|
|
|
cleanup() {
|
|
echo ""
|
|
echo "Cleaning up test data..."
|
|
./easyqemu vm delete test-vm-$$ -f 2>/dev/null || true
|
|
./easyqemu vm delete test-vm-clone-$$ -f 2>/dev/null || true
|
|
./easyqemu volume delete test-volume-$$.qcow2 -f 2>/dev/null || true
|
|
./easyqemu volume delete test-raw-$$.raw -f 2>/dev/null || true
|
|
./easyqemu volume delete test-converted-$$.qcow2 -f 2>/dev/null || true
|
|
./easyqemu repo delete test-template-$$ -f 2>/dev/null || true
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
cat << 'EOF'
|
|
╔═══════════════════════════════════════════════════════════════╗
|
|
║ EasyQEMU Test Suite ║
|
|
╚═══════════════════════════════════════════════════════════════╝
|
|
|
|
EOF
|
|
|
|
# Test 1: Help command
|
|
test_start "Help command"
|
|
if ./easyqemu help > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Help command failed"
|
|
fi
|
|
|
|
# Test 2: Version command
|
|
test_start "Version command"
|
|
if ./easyqemu version > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Version command failed"
|
|
fi
|
|
|
|
# Test 3: Create VM
|
|
test_start "Create VM"
|
|
if ./easyqemu vm create --name test-vm-$$ --memory 512 --cpus 1 --disk-size 1G > /dev/null 2>&1; then
|
|
VM_ID=$(./easyqemu vm list | grep "test-vm-$$" | awk '{print $1}')
|
|
if [[ -n "$VM_ID" ]]; then
|
|
test_pass
|
|
else
|
|
test_fail "VM was not created properly"
|
|
fi
|
|
else
|
|
test_fail "Failed to create VM"
|
|
fi
|
|
|
|
# Test 4: List VMs
|
|
test_start "List VMs"
|
|
if ./easyqemu vm list > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to list VMs"
|
|
fi
|
|
|
|
# Test 5: VM Info
|
|
test_start "VM Info"
|
|
if ./easyqemu vm info "$VM_ID" > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to get VM info"
|
|
fi
|
|
|
|
# Test 6: Modify VM
|
|
test_start "Modify VM"
|
|
if ./easyqemu vm modify "$VM_ID" --memory 1024 > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to modify VM"
|
|
fi
|
|
|
|
# Test 7: Create volume
|
|
test_start "Create volume"
|
|
if ./easyqemu volume create --name test-volume-$$ --size 1G --format qcow2 > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to create volume"
|
|
fi
|
|
|
|
# Test 8: List volumes
|
|
test_start "List volumes"
|
|
if ./easyqemu volume list > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to list volumes"
|
|
fi
|
|
|
|
# Test 9: Volume info
|
|
test_start "Volume info"
|
|
if ./easyqemu volume info ~/.easyqemu/volumes/test-volume-$$.qcow2 > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to get volume info"
|
|
fi
|
|
|
|
# Test 10: Convert volume
|
|
test_start "Convert volume"
|
|
qemu-img create -f raw ~/.easyqemu/volumes/test-raw-$$.raw 100M > /dev/null 2>&1
|
|
if ./easyqemu volume convert \
|
|
--source ~/.easyqemu/volumes/test-raw-$$.raw \
|
|
--target ~/.easyqemu/volumes/test-converted-$$.qcow2 \
|
|
--format qcow2 > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to convert volume"
|
|
fi
|
|
|
|
# Test 11: Create snapshot
|
|
test_start "Create snapshot"
|
|
if ./easyqemu snapshot create "$VM_ID" test-snapshot > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to create snapshot"
|
|
fi
|
|
|
|
# Test 12: List snapshots
|
|
test_start "List snapshots"
|
|
if ./easyqemu snapshot list "$VM_ID" > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to list snapshots"
|
|
fi
|
|
|
|
# Test 13: Delete snapshot
|
|
test_start "Delete snapshot"
|
|
if ./easyqemu snapshot delete "$VM_ID" test-snapshot > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to delete snapshot"
|
|
fi
|
|
|
|
# Test 14: Save to repository
|
|
test_start "Save to repository"
|
|
if ./easyqemu repo save "$VM_ID" test-template-$$ > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to save to repository"
|
|
fi
|
|
|
|
# Test 15: List repository
|
|
test_start "List repository"
|
|
if ./easyqemu repo list > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to list repository"
|
|
fi
|
|
|
|
# Test 16: Load from repository
|
|
test_start "Load from repository"
|
|
if ./easyqemu repo load test-template-$$ test-vm-clone-$$ > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to load from repository"
|
|
fi
|
|
|
|
# Test 17: Delete volume
|
|
test_start "Delete volume"
|
|
if ./easyqemu volume delete test-volume-$$.qcow2 -f > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to delete volume"
|
|
fi
|
|
|
|
# Test 18: Delete VM
|
|
test_start "Delete VM"
|
|
if ./easyqemu vm delete "$VM_ID" -f > /dev/null 2>&1; then
|
|
test_pass
|
|
else
|
|
test_fail "Failed to delete VM"
|
|
fi
|
|
|
|
# Summary
|
|
echo ""
|
|
echo "╔═══════════════════════════════════════════════════════════════╗"
|
|
echo "║ Test Results ║"
|
|
echo "╚═══════════════════════════════════════════════════════════════╝"
|
|
echo ""
|
|
echo -e "Total tests: $TESTS"
|
|
echo -e "${GREEN}Passed: $PASSED${NC}"
|
|
echo -e "${RED}Failed: $FAILED${NC}"
|
|
echo ""
|
|
|
|
if [[ $FAILED -eq 0 ]]; then
|
|
echo -e "${GREEN}All tests passed! ✓${NC}"
|
|
exit 0
|
|
else
|
|
echo -e "${RED}Some tests failed! ✗${NC}"
|
|
exit 1
|
|
fi
|