149 lines
3.8 KiB
Bash
Executable File
149 lines
3.8 KiB
Bash
Executable File
#! /usr/bin/env bats
|
|
|
|
# This is a test file for use with the bats testing framework
|
|
# https://github.com/bats-core/bats-core
|
|
# On Debian: apt install bats
|
|
|
|
function setup {
|
|
ORIGDIR="$(pwd)"
|
|
|
|
# If no $FORGEBUILD is supplied in ENV, use the default
|
|
# (otherwise you can't `bats ./tests/` manually)
|
|
[ -z "$FORGEBUILD" ] && FORGEBUILD="forgebuild"
|
|
|
|
# Ensure output from previous test does not exist
|
|
# (in case something crashed)
|
|
clean
|
|
|
|
# Setup simple git repository
|
|
GITREPO="$(mktemp -d)"
|
|
cd $GITREPO
|
|
git init
|
|
echo "first commit" > README
|
|
git add README
|
|
git commit -m "first commit"
|
|
|
|
# Setup forgebuild tasks
|
|
FORGEBUILDDIR="$(mktemp -d)"
|
|
echo "$GITREPO" > $FORGEBUILDDIR/time.source
|
|
echo "date +%s%N > /tmp/forgebuild-time" > $FORGEBUILDDIR/time
|
|
chmod +x $FORGEBUILDDIR/time
|
|
echo "$GITREPO" > $FORGEBUILDDIR/host.source
|
|
echo "cat \$GITBUILDCONF/entry > /tmp/forgebuild-host" > $FORGEBUILDDIR/host
|
|
chmod +x $FORGEBUILDDIR/host
|
|
|
|
# Setup settings
|
|
mkdir $FORGEBUILDDIR/config
|
|
echo "default" > $FORGEBUILDDIR/config/entry
|
|
mkdir $FORGEBUILDDIR/$HOSTNAME
|
|
echo "host" > $FORGEBUILDDIR/$HOSTNAME/entry
|
|
}
|
|
|
|
function teardown {
|
|
cd $ORIGDIR
|
|
clean
|
|
}
|
|
|
|
function clean {
|
|
if [ -d $GITREPO ]; then rm -rf $GITREPO; fi
|
|
if [ -d $FORGEBUILDDIR ]; then rm -rf $FORGEBUILDDIR; fi
|
|
if [ -f /tmp/forgebuild-time ]; then rm /tmp/forgebuild-time; fi
|
|
if [ -f /tmp/forgebuild-host ]; then rm /tmp/forgebuild-host; fi
|
|
}
|
|
|
|
function setup_submodule {
|
|
SUBMODULE="$(mktemp -d)"
|
|
cd $SUBMODULE
|
|
git init
|
|
echo "SUB" > README
|
|
git add README
|
|
git commit -m "first commit"
|
|
|
|
cd $GITREPO
|
|
git submodule add $SUBMODULE sub
|
|
git commit -m "add submodule"
|
|
}
|
|
|
|
@test "repository is cloned" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f $FORGEBUILDDIR/.time/README ]
|
|
}
|
|
|
|
@test "first run triggers task" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
}
|
|
|
|
@test "no update does not trigger task" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
TIME="$(cat /tmp/forgebuild-time)"
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
NEWTIME="$(cat /tmp/forgebuild-time)"
|
|
[[ "$TIME" = "$NEWTIME" ]]
|
|
}
|
|
|
|
@test "forced run triggers task" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
TIME="$(cat /tmp/forgebuild-time)"
|
|
$FORGEBUILD -f -b $FORGEBUILDDIR time
|
|
NEWTIME="$(cat /tmp/forgebuild-time)"
|
|
[[ "$TIME" != "$NEWTIME" ]]
|
|
}
|
|
|
|
@test "update triggers task" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
TIME="$(cat /tmp/forgebuild-time)"
|
|
cd $GITREPO
|
|
touch NEWFILE
|
|
git add NEWFILE
|
|
git commit -m "second commit"
|
|
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
NEWTIME="$(cat /tmp/forgebuild-time)"
|
|
|
|
[[ "$TIME" != "$NEWTIME" ]]
|
|
}
|
|
|
|
@test "host-based settings are loaded" {
|
|
$FORGEBUILD -b $FORGEBUILDDIR host
|
|
[[ "$(cat /tmp/forgebuild-host)" = "host" ]]
|
|
}
|
|
|
|
@test "unknown host uses default settings" {
|
|
HOST="UNKNOWN" $FORGEBUILD -b $FORGEBUILDDIR host
|
|
[[ "$(cat /tmp/forgebuild-host)" = "default" ]]
|
|
}
|
|
|
|
@test "submodule is cloned" {
|
|
setup_submodule
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f $FORGEBUILDDIR/.time/sub/README ]
|
|
[[ "$(cat $FORGEBUILDDIR/.time/sub/README)" = "SUB" ]]
|
|
}
|
|
|
|
@test "first submodule run triggers task" {
|
|
setup_submodule
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
}
|
|
|
|
@test "submodule update does not trigger task by default" {
|
|
setup_submodule
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
[ -f /tmp/forgebuild-time ]
|
|
TIME="$(cat /tmp/forgebuild-time)"
|
|
|
|
cd $SUBMODULE
|
|
echo "new stuff" > NEWFILE
|
|
git add NEWFILE
|
|
git commit -m "second commit"
|
|
|
|
$FORGEBUILD -b $FORGEBUILDDIR time
|
|
NEWTIME="$(cat /tmp/forgebuild-time)"
|
|
|
|
[[ "$TIME" = "$NEWTIME" ]]
|
|
}
|