gitpages

A collection of scripts to securely webhost and publish git repositories.
git clone https://scm.kuandu.systems/git-raw/gitpages.git
Log | Files | Refs | README | LICENSE

test-gitpages-process-queue.sh (1520B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 # Configuration
      6 TEST_DIR=$(realpath "$(mktemp -d)")
      7 
      8 export GITPAGES_LOCK_DIR="$TEST_DIR/lock"
      9 export GITPAGES_QUEUE_DIR="$TEST_DIR/queue"
     10 export GITPAGES_LOG_FILE="$TEST_DIR/log.txt"
     11 export GITPAGES_VAR_DIR="$TEST_DIR/var"
     12 
     13 CONFIG_FILE="$TEST_DIR/gitpages.conf"
     14 
     15 WEB_ROOT="$TEST_DIR"
     16 GIT_SRC="$TEST_DIR/src"
     17 GIT_RAW="raw"
     18 REPO_PATH="$GIT_SRC/myrepo.git"
     19 GIT_HTML="git"
     20 
     21 # Mock dependencies
     22 mkdir -p "$TEST_DIR/bin"
     23 export PATH="$TEST_DIR/bin:$PATH"
     24 
     25 mock_bin() {
     26   cat << EOF > "$TEST_DIR/bin/$1"
     27 #!/bin/sh
     28 printf "MOCK: %s called with \$*\n" "$1" >&2
     29 exit 0
     30 EOF
     31   chmod +x "$TEST_DIR/bin/$1"
     32 }
     33 
     34 mock_bin git
     35 mock_bin stagit
     36 mock_bin stagit-index
     37 
     38 # Setup test environment
     39 mkdir -p "$GITPAGES_QUEUE_DIR"
     40 mkdir -p "$GIT_SRC"
     41 mkdir -p "$REPO_PATH"
     42 mkdir -p "$WEB_ROOT/$GIT_HTML"
     43 mkdir -p "$WEB_ROOT/$GIT_RAW"
     44 
     45 # Create a job file whose content is the repo path
     46 printf '%s\n' "$REPO_PATH" > "$GITPAGES_QUEUE_DIR/myrepo"
     47 
     48 # Create test config
     49 cat << EOF > "$CONFIG_FILE"
     50 WEB_ROOT=$TEST_DIR
     51 GIT_RAW=$GIT_RAW
     52 GIT_HTML=$GIT_HTML
     53 GIT_SRC=$GIT_SRC
     54 EOF
     55 
     56 echo "Running test on gitpages.sh..."
     57 ./gitpages.sh process_queue -c "$CONFIG_FILE"
     58 
     59 # Verify: queue directory should be empty (no job files left)
     60 files=$(find "$GITPAGES_QUEUE_DIR" -type f | wc -l)
     61 if [ "$files" -eq 0 ]; then
     62   echo "PASS: Queue directory is empty."
     63 else
     64   echo "FAIL: Queue directory is not empty (has $files files)."
     65   find "$GITPAGES_QUEUE_DIR" -type f
     66   exit 1
     67 fi
     68 
     69 rm -rf "$TEST_DIR"
     70 echo "PASS: process_queue executed successfully."