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-update.sh (2073B)


      1 #!/bin/sh
      2 #
      3 # Copyright (c) 2026 Fred Großkopf
      4 #
      5 # Permission to use, copy, modify, and/or distribute this software for any
      6 # purpose with or without fee is hereby granted, provided that the above
      7 # copyright notice and this permission notice appear in all copies.
      8 #
      9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16 
     17 set -e
     18 
     19 # Configuration
     20 TEST_DIR=$(realpath "$(mktemp -d)")
     21 
     22 export GITPAGES_LOCK_DIR="$TEST_DIR/lock"
     23 export GITPAGES_QUEUE_DIR="$TEST_DIR/queue"
     24 export GITPAGES_LOG_FILE="$TEST_DIR/log.txt"
     25 
     26 CONFIG_FILE="$TEST_DIR/gitpages.conf"
     27 GIT_RAW="$TEST_DIR/raw"
     28 REPO_PATH="$GIT_RAW/myrepo.git"
     29 
     30 # Mock dependencies
     31 mkdir -p "$TEST_DIR/bin"
     32 export PATH="$TEST_DIR/bin:$PATH"
     33 
     34 mock_bin() {
     35   cat << EOF > "$TEST_DIR/bin/$1"
     36 #!/bin/sh
     37 printf "MOCK: %s called with \$*\n" "$1" >&2
     38 exit 0
     39 EOF
     40   chmod +x "$TEST_DIR/bin/$1"
     41 }
     42 
     43 mock_bin gitpages-mirror-git.sh
     44 mock_bin gitpages.sh
     45 
     46 # Setup test environment
     47 mkdir -p "$GIT_RAW"
     48 mkdir -p "$GITPAGES_QUEUE_DIR"
     49 mkdir -p "$REPO_PATH"
     50 
     51 # Create a job file whose content is the repo path
     52 printf '%s\n' "$REPO_PATH" > "$GITPAGES_QUEUE_DIR/myrepo"
     53 
     54 # Create test config
     55 cat << EOF > "$CONFIG_FILE"
     56 GIT_RAW=$GIT_RAW
     57 EOF
     58 
     59 echo "Running test on gitpages-update.sh..."
     60 ./gitpages-update.sh -c "$CONFIG_FILE"
     61 
     62 # Verify: queue directory should be empty (no job files left)
     63 files=$(find "$GITPAGES_QUEUE_DIR" -type f | wc -l)
     64 if [ "$files" -eq 0 ]; then
     65   echo "PASS: Queue directory is empty."
     66 else
     67   echo "FAIL: Queue directory is not empty (has $files files)."
     68   find "$GITPAGES_QUEUE_DIR" -type f
     69   exit 1
     70 fi
     71 
     72 rm -rf "$TEST_DIR"
     73 echo "PASS: Update script executed successfully."