#!/bin/bash # Setup Test Environment for apt-ostree # This script sets up a test environment for validating apt-ostree functionality set -e echo "๐Ÿงช Setting up apt-ostree test environment..." # Configuration TEST_DIR="/tmp/apt-ostree-test" OSTREE_REPO="$TEST_DIR/repo" DEPLOY_DIR="$TEST_DIR/deploy" APT_OSTREE_BIN="./target/release/simple-cli" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if apt-ostree binary exists if [ ! -f "$APT_OSTREE_BIN" ]; then print_error "apt-ostree binary not found at $APT_OSTREE_BIN" print_status "Building apt-ostree..." cargo build --bin simple-cli --release fi # Create test directory structure print_status "Creating test directory structure..." mkdir -p "$TEST_DIR" mkdir -p "$OSTREE_REPO" mkdir -p "$DEPLOY_DIR" # Initialize OSTree repository print_status "Initializing OSTree repository..." if command -v ostree &> /dev/null; then ostree --repo="$OSTREE_REPO" init --mode=bare print_success "OSTree repository initialized" else print_warning "ostree command not found - skipping repository initialization" fi # Test basic apt-ostree functionality print_status "Testing basic apt-ostree functionality..." # Test 1: Help command print_status "Test 1: Help command" if $APT_OSTREE_BIN --help > /dev/null 2>&1; then print_success "Help command works" else print_error "Help command failed" fi # Test 2: Status command print_status "Test 2: Status command" if $APT_OSTREE_BIN status > /dev/null 2>&1; then print_success "Status command works" else print_error "Status command failed" fi # Test 3: List command print_status "Test 3: List command" if $APT_OSTREE_BIN list > /dev/null 2>&1; then print_success "List command works" else print_error "List command failed" fi # Test 4: Search command print_status "Test 4: Search command" if $APT_OSTREE_BIN search bash > /dev/null 2>&1; then print_success "Search command works" else print_error "Search command failed" fi # Test 5: OCI commands print_status "Test 5: OCI commands" if $APT_OSTREE_BIN oci --help > /dev/null 2>&1; then print_success "OCI commands work" else print_error "OCI commands failed" fi # Create test configuration print_status "Creating test configuration..." cat > "$TEST_DIR/test-config.json" << EOF { "ostree": { "repo_path": "$OSTREE_REPO", "deploy_path": "$DEPLOY_DIR", "branch": "test/debian/stable" }, "apt": { "sources": [ "deb http://deb.debian.org/debian stable main", "deb http://deb.debian.org/debian-security stable-security main", "deb http://deb.debian.org/debian stable-updates main" ] }, "test_packages": [ "bash", "coreutils", "dpkg", "apt", "systemd" ] } EOF print_success "Test configuration created" # Create test script print_status "Creating test script..." cat > "$TEST_DIR/run-tests.sh" << 'EOF' #!/bin/bash # Test script for apt-ostree functionality set -e APT_OSTREE_BIN="./target/release/simple-cli" TEST_DIR="/tmp/apt-ostree-test" echo "๐Ÿงช Running apt-ostree tests..." # Test basic commands echo "Testing basic commands..." $APT_OSTREE_BIN status $APT_OSTREE_BIN list | head -10 $APT_OSTREE_BIN search bash | head -5 # Test OCI functionality echo "Testing OCI functionality..." $APT_OSTREE_BIN oci --help echo "โœ… All tests completed successfully!" EOF chmod +x "$TEST_DIR/run-tests.sh" print_success "Test script created" # Create OCI test script print_status "Creating OCI test script..." cat > "$TEST_DIR/test-oci.sh" << 'EOF' #!/bin/bash # OCI test script for apt-ostree set -e APT_OSTREE_BIN="./target/release/simple-cli" TEST_DIR="/tmp/apt-ostree-test" echo "๐Ÿณ Testing OCI functionality..." # Test OCI build (this will fail without a real OSTree commit, but we can test the command structure) echo "Testing OCI build command structure..." $APT_OSTREE_BIN oci build --help # Test OCI inspect echo "Testing OCI inspect command structure..." $APT_OSTREE_BIN oci inspect --help # Test OCI validate echo "Testing OCI validate command structure..." $APT_OSTREE_BIN oci validate --help echo "โœ… OCI command structure tests completed!" EOF chmod +x "$TEST_DIR/test-oci.sh" print_success "OCI test script created" print_success "Test environment setup complete!" echo "" echo "๐Ÿ“ Test environment created at: $TEST_DIR" echo "๐Ÿ“ฆ OSTree repository: $OSTREE_REPO" echo "๐Ÿ”ง apt-ostree binary: $APT_OSTREE_BIN" echo "" echo "๐Ÿš€ Next steps:" echo "1. Run basic tests: $TEST_DIR/run-tests.sh" echo "2. Test OCI functionality: $TEST_DIR/test-oci.sh" echo "3. Test package operations: $APT_OSTREE_BIN install " echo "4. Test system operations: $APT_OSTREE_BIN upgrade" echo "" echo "๐Ÿ“‹ Test commands:" echo "- Status: $APT_OSTREE_BIN status" echo "- List packages: $APT_OSTREE_BIN list" echo "- Search packages: $APT_OSTREE_BIN search " echo "- Show info: $APT_OSTREE_BIN info " echo "- OCI build: $APT_OSTREE_BIN oci build "