Tests for sourceless tasks

This commit is contained in:
southerntofu 2020-09-17 15:49:05 +02:00
parent 7010d311f1
commit dbad736d0a
1 changed files with 77 additions and 0 deletions

77
tests/sourceless.bats Normal file
View File

@ -0,0 +1,77 @@
#! /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 forgebuild tasks
FORGEBUILDDIR="$(mktemp -d)"
echo "date +%s%N > /tmp/forgebuild-time" > $FORGEBUILDDIR/time
chmod +x $FORGEBUILDDIR/time
# 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 $FORGEBUILDDIR ]; then rm -rf $FORGEBUILDDIR; fi
if [ -f /tmp/forgebuild-time ]; then rm /tmp/forgebuild-time; fi
}
# Simple repository
@test "sourceless task runs only once" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
[ -f $FORGEBUILDDIR/time.done ]
TIME="$(cat /tmp/forgebuild-time)"
$FORGEBUILD -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}
@test "sourceless task is not forced triggered by --force flag" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
[ -f $FORGEBUILDDIR/time.done ]
TIME="$(cat /tmp/forgebuild-time)"
$FORGEBUILD -f -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}
@test "sourceless task can run on specific hosts" {
echo "$HOSTNAME" > $FORGEBUILDDIR/time.hosts
$FORGEBUILD -b $FORGEBUILDDIR time
TIME="$(cat /tmp/forgebuild-time)"
HOST="UNKNOWN" $FORGEBUILD -b $FORGEBUILDDIR time
NEWTIME="$(cat /tmp/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}
@test "sourceless task can be ignored on hosts" {
touch $FORGEBUILDDIR/$HOSTNAME/time.ignore
$FORGEBUILD -b $FORGEBUILDDIR time
[ ! -f /tmp/forgebuild-time ]
HOST="UNKNOWN" $FORGEBUILD -b $FORGEBUILDDIR time
[ -f /tmp/forgebuild-time ]
}