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


      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 SCRIPT_NAME="./gitpages.sh"
     21 TEST_DIR=$(realpath "$(mktemp -d)")
     22 
     23 # --- Cleanup ---
     24 cleanup() {
     25   rm -rf "$TEST_DIR"
     26 }
     27 trap cleanup EXIT
     28 
     29 # --- Prerequisites ---
     30 [ -x "$SCRIPT_NAME" ] || {
     31   echo "ERROR: $SCRIPT_NAME missing or not executable"
     32   exit 1
     33 }
     34 command -v stagit-index > /dev/null 2>&1 || {
     35   echo "ERROR: stagit-index missing"
     36   exit 1
     37 }
     38 
     39 # --- Directory layout expected by gitpages.sh ---
     40 WEB_ROOT="$TEST_DIR/public"
     41 GIT_RAW_DIR="$WEB_ROOT/raw"
     42 GIT_HTML_DIR="$WEB_ROOT/html"
     43 STAGING_ROOT="$TEST_DIR/staging" # we'll point VAR_DIR here
     44 
     45 mkdir -p "$GIT_RAW_DIR" "$GIT_HTML_DIR" "$TEST_DIR/assets" "$STAGING_ROOT"
     46 
     47 # --- Dummy repo ---
     48 REPO_NAME="myrepo"
     49 REPO_DIR="$GIT_RAW_DIR/$REPO_NAME.git"
     50 mkdir -p "$REPO_DIR"
     51 (cd "$REPO_DIR" && git init --bare > /dev/null 2>&1)
     52 
     53 # --- Config (VAR_DIR now set here) ---
     54 CONFIG_FILE="$TEST_DIR/gitpages.conf"
     55 cat << EOF > "$CONFIG_FILE"
     56 WEB_ROOT=$WEB_ROOT
     57 GIT_HTML=html
     58 GIT_RAW=raw
     59 ASSETS_DIR=$TEST_DIR/assets
     60 EOF
     61 
     62 # --- Assets (for deploy_assets) ---
     63 echo "<!-- dummy logo -->" > "$TEST_DIR/assets/logo.svg"
     64 echo "<!-- dummy style -->" > "$TEST_DIR/assets/style.css"
     65 
     66 # --- Execution ---
     67 export GITPAGES_VAR_DIR="$TEST_DIR"
     68 echo "Running $SCRIPT_NAME on $REPO_DIR"
     69 "$SCRIPT_NAME" -c "$CONFIG_FILE" "$REPO_DIR"
     70 
     71 # --- Verification ---
     72 EXPECTED_REPO_DIR="$GIT_HTML_DIR/$REPO_NAME"
     73 EXPECTED_INDEX="$GIT_HTML_DIR/index.html"
     74 
     75 if [ -d "$EXPECTED_REPO_DIR" ] && [ -f "$EXPECTED_INDEX" ]; then
     76   echo "PASS: per‑repo HTML and index generated successfully"
     77 else
     78   echo "FAIL: missing repo or index"
     79   ls -R "$TEST_DIR"
     80   exit 1
     81 fi
     82 
     83 # --- Staging cleanup check ---
     84 STAGING_DIR="$TEST_DIR/staging/$REPO_NAME"
     85 if [ -d "$STAGING_DIR" ]; then
     86   echo "FAIL: staging directory still present at $STAGING_DIR"
     87   ls -R "$TEST_DIR/staging"
     88   exit 1
     89 fi
     90 
     91 echo "PASS: staging used and then cleaned up"