diff options
| author | hc <hc@email.ch> | 2025-05-31 23:44:40 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-05-31 23:44:40 +0800 |
| commit | d6eb567da3e6d2e64ebf22adf1fc6d21c47090f8 (patch) | |
| tree | 14c15830a8014001d5cc587b5b4d4454c880396e /tests/test_base_container.sh | |
| parent | ce511f49438761549e904d6e972b8c0635306ff9 (diff) | |
hehe
Diffstat (limited to 'tests/test_base_container.sh')
| -rwxr-xr-x | tests/test_base_container.sh | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/test_base_container.sh b/tests/test_base_container.sh new file mode 100755 index 0000000..b5115ec --- /dev/null +++ b/tests/test_base_container.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +# Container Test Script for rocky_dev:latest +# This script tests all the functionality of the base container + +set -e + +CONTAINER_NAME="rocky_dev_test_$$" +IMAGE_NAME="rocky_dev:latest" +TEST_PORT=$(shuf -i 30000-40000 -n 1) + +# Cleanup function +cleanup() { + echo "" + echo "Cleaning up..." + podman stop $CONTAINER_NAME >/dev/null 2>&1 || true + podman rm $CONTAINER_NAME >/dev/null 2>&1 || true + echo "Container $CONTAINER_NAME removed" +} + +# Set trap to cleanup on exit +trap cleanup EXIT + +echo "=== Rocky Dev Container Test Suite ===" +echo "Container: $CONTAINER_NAME" +echo "Port: $TEST_PORT" +echo "" + +# Function to run commands in container +run_in_container() { + podman exec $CONTAINER_NAME bash -c "$1" +} + +# Function to check if command exists +check_command() { + local cmd=$1 + echo -n "Checking $cmd... " + if run_in_container "command -v $cmd" >/dev/null 2>&1; then + echo "✓" + return 0 + else + echo "✗" + return 1 + fi +} + +# Start container +echo "1. Starting container..." +podman run -d -p ${TEST_PORT}:22 --name $CONTAINER_NAME $IMAGE_NAME +sleep 5 + +echo "" +echo "2. Testing system packages..." +# Test core development tools +check_command gcc +check_command g++ +check_command make +check_command cmake +check_command git +check_command python3 +check_command pip3 + +echo "" +echo "3. Testing system utilities..." +# Test system utilities +check_command tmux +check_command vim +check_command nano +check_command tree +check_command htop +check_command bmon +check_command wget +check_command nc +check_command bat + +echo "" +echo "4. Testing SSH configuration..." +# Check SSH daemon +run_in_container "ps aux | grep sshd | grep -v grep" && echo "✓ SSH daemon running" || echo "✗ SSH daemon not running" + +# Check SSH config +run_in_container "grep -q 'PubkeyAuthentication yes' /etc/ssh/sshd_config" && echo "✓ PubkeyAuthentication enabled" || echo "✗ PubkeyAuthentication not enabled" +run_in_container "grep -q 'PermitRootLogin yes' /etc/ssh/sshd_config" && echo "✓ PermitRootLogin enabled" || echo "✗ PermitRootLogin not enabled" + +# Check SSH directory +run_in_container "test -d /root/.ssh && test -f /root/.ssh/authorized_keys" && echo "✓ SSH directory configured" || echo "✗ SSH directory not configured" + +echo "" +echo "5. Testing Rust installation..." +# Test Rust +run_in_container "source /root/.cargo/env && cargo --version" && echo "✓ Cargo installed" || echo "✗ Cargo not installed" +run_in_container "source /root/.cargo/env && rustc --version" && echo "✓ Rust compiler installed" || echo "✗ Rust compiler not installed" + +# Test Rust tools +echo "Checking Rust tools..." +for tool in cargo-clone cargo-add cargo-info bacon dust; do + run_in_container "source /root/.cargo/env && command -v $tool" >/dev/null 2>&1 && echo " ✓ $tool" || echo " ✗ $tool" +done +# Check evcxr_jupyter separately (it's a Jupyter kernel, not a CLI tool) +run_in_container "source /root/.cargo/env && ls ~/.cargo/bin/evcxr_jupyter" >/dev/null 2>&1 && echo " ✓ evcxr_jupyter (Rust Jupyter kernel)" || echo " ✗ evcxr_jupyter" + +echo "" +echo "6. Testing Node.js installation..." +# Test Node.js +run_in_container "source /root/.nvm/nvm.sh && node --version" && echo "✓ Node.js installed" || echo "✗ Node.js not installed" +run_in_container "source /root/.nvm/nvm.sh && npm --version" && echo "✓ npm installed" || echo "✗ npm not installed" + +# Test claude-code +run_in_container "source /root/.nvm/nvm.sh && claude --version" >/dev/null 2>&1 && echo "✓ claude-code installed" || echo "✗ claude-code not installed" + +echo "" +echo "7. Testing environment configuration..." +# Test bash configuration +run_in_container "grep -q 'LS_COLORS' /etc/bashrc" && echo "✓ LS_COLORS configured" || echo "✗ LS_COLORS not configured" +run_in_container "grep -q 'PS1=' /etc/bashrc" && echo "✓ Custom prompt configured" || echo "✗ Custom prompt not configured" + +echo "" +echo "8. Testing SSH connectivity..." +# Test SSH connection (this will fail without proper keys) +echo -n "Testing SSH port accessibility... " +nc -zv localhost $TEST_PORT 2>&1 | grep -q succeeded && echo "✓" || echo "✗" + +echo "" +echo "9. Testing file system..." +# Check working directory +run_in_container "pwd" | grep -q "/root" && echo "✓ Working directory is /root" || echo "✗ Working directory incorrect" + +echo "" +echo "=== Test Summary ===" +echo "All tests completed successfully!" +echo "Container will be automatically cleaned up."
\ No newline at end of file |
