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


      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 CONFIG_FILE="$TEST_DIR/gitpages.conf"
     22 GIT_SRC="$TEST_DIR/src"
     23 GIT_RAW="$TEST_DIR/raw"
     24 ASSETS_DIR="$TEST_DIR/assets"
     25 
     26 # Mock dependencies so we don't need real binaries
     27 mkdir -p "$TEST_DIR/bin"
     28 export PATH="$TEST_DIR/bin:$PATH"
     29 
     30 # The mock script correctly uses the filename as the identifier
     31 mock_bin() {
     32     cat << EOF > "$TEST_DIR/bin/$1"
     33 #!/bin/sh
     34 echo "MOCK: $1 called with \$*"
     35 exit 0
     36 EOF
     37     chmod +x "$TEST_DIR/bin/$1"
     38 }
     39 
     40 # Generate mocks
     41 mock_bin gitpages-mirror-git.sh
     42 mock_bin gitpages.sh
     43 mock_bin git
     44 mock_bin stagit
     45 mock_bin stagit-index
     46 
     47 # Setup test environment
     48 mkdir -p "$GIT_SRC" "$GIT_RAW" "$ASSETS_DIR"
     49 
     50 # Create at least one dummy repo file so the loop in gitpages-regenerate.sh triggers
     51 touch "$GIT_RAW/myrepo.git"
     52 
     53 # Create test config
     54 cat <<EOF > "$CONFIG_FILE"
     55 GIT_SRC=$GIT_SRC
     56 GIT_RAW=$GIT_RAW
     57 EOF
     58 
     59 echo "Running test on gitpages-regenerate.sh..."
     60 ./gitpages-regenerate.sh -c "$CONFIG_FILE"
     61 
     62 # Clean up
     63 rm -rf "$TEST_DIR"
     64 echo "PASS: Init script executed successfully."