#!/usr/bin/env bash
set -e
POSTGRES_URL="${1:-postgres://secafs:secafs@localhost:5432/test}"
CLI="${CLI:-./target/debug/secafs}"
MOUNT_POINT="${MOUNT_POINT:-/tmp/secafs_e2e_mnt}"
if ! [[ "$POSTGRES_URL" =~ ^postgres(ql)?:// ]]; then
echo "Usage: $0 [POSTGRES_URL]"
echo "Example: $0 postgres://secafs:secafs@localhost:5432/test"
exit 1
fi
cd "$(dirname "$0")/.."
CLI_DIR="$(pwd)/cli"
if [[ ! -x "$CLI_DIR/target/debug/secafs" && ! -x "$CLI_DIR/target/release/secafs" ]]; then
echo "Building CLI (no-default-features)..."
(cd "$CLI_DIR" && cargo build --no-default-features)
fi
if [[ -x "$CLI_DIR/target/release/secafs" ]]; then
CLI="$CLI_DIR/target/release/secafs"
else
CLI="$CLI_DIR/target/debug/secafs"
fi
echo "=== SecAFS CLI E2E (PostgreSQL) ==="
echo "POSTGRES_URL=$POSTGRES_URL"
echo "CLI=$CLI"
echo ""
echo "--- 1. secafs --help ---"
"$CLI" --help
echo ""
echo "--- 2. secafs init ---"
"$CLI" init "$POSTGRES_URL"
echo ""
echo "--- 3. secafs fs ls / ---"
"$CLI" fs "$POSTGRES_URL" ls /
echo ""
echo "--- 4. secafs fs write + cat ---"
"$CLI" fs "$POSTGRES_URL" write /e2e_hello.txt "Hello from CLI E2E"
"$CLI" fs "$POSTGRES_URL" cat /e2e_hello.txt
echo ""
echo "--- 5. secafs fs ls / (after write) ---"
"$CLI" fs "$POSTGRES_URL" ls /
echo ""
if [[ "$(uname)" == "Linux" ]] && command -v fusermount3 &>/dev/null; then
echo "--- 6. secafs mount (3s 后卸载) ---"
mkdir -p "$MOUNT_POINT"
"$CLI" mount "$POSTGRES_URL" "$MOUNT_POINT" -f &
MPID=$!
sleep 3
fusermount3 -u "$MOUNT_POINT" 2>/dev/null || fusermount -u "$MOUNT_POINT" 2>/dev/null || true
kill $MPID 2>/dev/null || true
rmdir "$MOUNT_POINT" 2>/dev/null || true
echo "mount test done"
else
echo "--- 6. mount skip (非 Linux 或无 fusermount) ---"
fi
echo ""
echo "=== E2E 完成 ==="