particle-os-tools/test-simple-rollback.sh
2025-07-14 09:12:46 -07:00

165 lines
No EOL
4 KiB
Bash

#!/bin/bash
# Simple Particle-OS Rollback Test
# Quick validation of basic rollback functionality
set -euo pipefail
echo "=== Particle-OS Simple Rollback Test ==="
echo "Testing basic rollback functionality..."
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Test counters
PASSED=0
FAILED=0
# Simple test function
test_command() {
local cmd="$1"
local description="$2"
echo -n "Testing: $description... "
if eval "$cmd" >/dev/null 2>&1; then
echo -e "${GREEN}PASS${NC}"
((PASSED++))
else
echo -e "${RED}FAIL${NC}"
((FAILED++))
fi
}
# Check if tools exist
echo "=== Tool Availability ==="
test_command "which apt-layer.sh || test -f ./apt-layer.sh" "apt-layer.sh exists"
test_command "which jq" "jq exists"
test_command "which ostree" "ostree exists"
echo ""
# Test basic commands
echo "=== Basic Commands ==="
test_command "./apt-layer.sh --help" "apt-layer help works"
test_command "./apt-layer.sh status" "apt-layer status works"
echo ""
# Test initialization
echo "=== Initialization ==="
if ! ./apt-layer.sh status 2>/dev/null | grep -q "Initialized"; then
echo -n "Initializing apt-layer... "
if ./apt-layer.sh --init >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
else
echo -e "${BLUE}Already initialized${NC}"
((PASSED++))
fi
echo ""
# Test OSTree commands
echo "=== OSTree Commands ==="
test_command "./apt-layer.sh ostree status" "OSTree status works"
test_command "./apt-layer.sh ostree log" "OSTree log works"
echo ""
# Test commit creation
echo "=== Commit Creation ==="
echo -n "Creating test commit... "
if ./apt-layer.sh ostree compose install htop >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
echo -n "Creating second commit... "
if ./apt-layer.sh ostree compose install curl >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
echo ""
# Test rollback preparation
echo "=== Rollback Preparation ==="
echo -n "Preparing rollback... "
commits=($(./apt-layer.sh ostree log 2>/dev/null | grep -o "ostree-[0-9]*-[0-9]*" || echo ""))
if [[ ${#commits[@]} -ge 2 ]]; then
if ./apt-layer.sh ostree rollback "${commits[1]}" >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
else
echo -e "${YELLOW}SKIPPED (not enough commits)${NC}"
fi
echo ""
# Test live overlay
echo "=== Live Overlay ==="
echo -n "Starting live overlay... "
if ./apt-layer.sh --live-overlay start >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
echo -n "Installing package in overlay... "
if ./apt-layer.sh --live-install sl >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
echo -n "Rolling back overlay... "
if ./apt-layer.sh --live-overlay rollback >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
echo -n "Stopping live overlay... "
if ./apt-layer.sh --live-overlay stop >/dev/null 2>&1; then
echo -e "${GREEN}SUCCESS${NC}"
((PASSED++))
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
else
echo -e "${RED}FAILED${NC}"
((FAILED++))
fi
echo ""
# Results
echo "=== Test Results ==="
echo "Total Tests: $((PASSED + FAILED))"
echo -e "Passed: ${GREEN}$PASSED${NC}"
echo -e "Failed: ${RED}$FAILED${NC}"
echo ""
if [[ $FAILED -eq 0 ]]; then
echo -e "${GREEN}🎉 All tests passed! Particle-OS rollback functionality is working correctly.${NC}"
exit 0
else
echo -e "${RED}⚠️ Some tests failed. Please check the system and try again.${NC}"
exit 1
fi