#!/bin/bash # Test script for apt-ostree Status command implementation set -e echo "๐Ÿงช Testing apt-ostree Status Command Implementation" echo "==================================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color log() { echo -e "${GREEN}[INFO]${NC} $1" } warn() { echo -e "${YELLOW}[WARN]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" } # Step 1: Check if apt-ostree binary exists log "1. Checking apt-ostree binary..." if [ -f /usr/bin/apt-ostree ]; then log "โœ… apt-ostree binary found at /usr/bin/apt-ostree" APT_OSTREE_BIN="/usr/bin/apt-ostree" elif [ -f target/release/apt-ostree ]; then log "โœ… apt-ostree binary found at target/release/apt-ostree" APT_OSTREE_BIN="target/release/apt-ostree" elif [ -f target/debug/apt-ostree ]; then log "โœ… apt-ostree binary found at target/debug/apt-ostree" APT_OSTREE_BIN="target/debug/apt-ostree" else error "โŒ apt-ostree binary not found" log "Building apt-ostree..." cargo build --release APT_OSTREE_BIN="target/release/apt-ostree" fi # Step 2: Test basic status command log "2. Testing basic status command..." STATUS_OUTPUT=$($APT_OSTREE_BIN status 2>&1) if [ $? -eq 0 ]; then log "โœ… Status command executed successfully" echo "Output:" echo "$STATUS_OUTPUT" | head -10 else error "โŒ Status command failed: $STATUS_OUTPUT" fi # Step 3: Test status with JSON output log "3. Testing status with JSON output..." JSON_OUTPUT=$($APT_OSTREE_BIN status --json 2>&1) if [ $? -eq 0 ]; then log "โœ… Status JSON command executed successfully" echo "JSON Output:" echo "$JSON_OUTPUT" | head -5 else error "โŒ Status JSON command failed: $JSON_OUTPUT" fi # Step 4: Test status with verbose output log "4. Testing status with verbose output..." VERBOSE_OUTPUT=$($APT_OSTREE_BIN status --verbose 2>&1) if [ $? -eq 0 ]; then log "โœ… Status verbose command executed successfully" echo "Verbose Output:" echo "$VERBOSE_OUTPUT" | head -10 else error "โŒ Status verbose command failed: $VERBOSE_OUTPUT" fi # Step 5: Test status with booted-only flag log "5. Testing status with booted-only flag..." BOOTED_OUTPUT=$($APT_OSTREE_BIN status --booted 2>&1) if [ $? -eq 0 ]; then log "โœ… Status booted command executed successfully" echo "Booted Output:" echo "$BOOTED_OUTPUT" | head -5 else error "โŒ Status booted command failed: $BOOTED_OUTPUT" fi # Step 6: Test status with advisories flag log "6. Testing status with advisories flag..." ADVISORIES_OUTPUT=$($APT_OSTREE_BIN status --advisories 2>&1) if [ $? -eq 0 ]; then log "โœ… Status advisories command executed successfully" echo "Advisories Output:" echo "$ADVISORIES_OUTPUT" | head -5 else error "โŒ Status advisories command failed: $ADVISORIES_OUTPUT" fi # Step 7: Test status with pending exit 77 flag log "7. Testing status with pending exit 77 flag..." PENDING_OUTPUT=$($APT_OSTREE_BIN status --pending-exit-77 2>&1) PENDING_EXIT_CODE=$? if [ $PENDING_EXIT_CODE -eq 77 ]; then log "โœ… Status pending exit 77 command executed correctly (exit 77)" echo "Pending Output:" echo "$PENDING_OUTPUT" | head -5 elif [ $PENDING_EXIT_CODE -eq 0 ]; then log "โœ… Status pending exit 77 command executed (no pending deployment)" echo "No Pending Output:" echo "$PENDING_OUTPUT" | head -5 else error "โŒ Status pending exit 77 command failed: $PENDING_OUTPUT" fi # Step 8: Test daemon communication log "8. Testing daemon communication..." if systemctl is-active --quiet apt-ostreed.service 2>/dev/null; then log "โœ… Daemon service is active" # Test daemon ping DAEMON_PING=$($APT_OSTREE_BIN daemon-ping 2>&1) if [ $? -eq 0 ]; then log "โœ… Daemon ping successful: $DAEMON_PING" else warn "โš ๏ธ Daemon ping failed: $DAEMON_PING" fi # Test daemon status DAEMON_STATUS=$($APT_OSTREE_BIN daemon-status 2>&1) if [ $? -eq 0 ]; then log "โœ… Daemon status successful" echo "Daemon Status:" echo "$DAEMON_STATUS" | head -5 else warn "โš ๏ธ Daemon status failed: $DAEMON_STATUS" fi else warn "โš ๏ธ Daemon service is not active" fi # Step 9: Test fallback functionality log "9. Testing fallback functionality..." if ! systemctl is-active --quiet apt-ostreed.service 2>/dev/null; then log "Daemon not active, testing fallback..." FALLBACK_OUTPUT=$($APT_OSTREE_BIN status 2>&1) if [ $? -eq 0 ]; then log "โœ… Fallback status command executed successfully" echo "Fallback Output:" echo "$FALLBACK_OUTPUT" | head -5 else error "โŒ Fallback status command failed: $FALLBACK_OUTPUT" fi fi echo "" echo "๐ŸŽ‰ Status Command Test Summary" echo "==============================" log "Status command implementation test completed" log "Check the output above for any errors or warnings" log "The Status command should now provide rich deployment information" log "with support for JSON output, verbose mode, and various filtering options"