build/tests/12-mercurial.bats

114 lines
3.1 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)"
TMPDIR="$(mktemp -d)"
# If no $FORGEBUILD is supplied in ENV, use the default
# (otherwise you can't `bats ./tests/` manually)
[ -z "$FORGEBUILD" ] && FORGEBUILD="forgebuild"
# Setup simple git repository
REPO="$TMPDIR"/hg
mkdir $REPO
cd $REPO
hg init
echo "first commit" > README
hg add README
hg commit -m "first commit"
# Setup forgebuild tasks
FORGEBUILDDIR="$TMPDIR"/forgebuild
mkdir $FORGEBUILDDIR
echo "$REPO" > $FORGEBUILDDIR/time.source
echo "mercurial" > $FORGEBUILDDIR/time.dvcs
echo "date +%s%N > $TMPDIR/forgebuild-time" > $FORGEBUILDDIR/time
chmod +x $FORGEBUILDDIR/time
echo "$REPO" > $FORGEBUILDDIR/host.source
echo "mercurial" > $FORGEBUILDDIR/host.dvcs
echo "cat \$FORGEBUILDCONF/entry > $TMPDIR/forgebuild-host" > $FORGEBUILDDIR/host
chmod +x $FORGEBUILDDIR/host
echo "$REPO" > $FORGEBUILDDIR/branch.source
echo "mercurial" > $FORGEBUILDDIR/branch.dvcs
echo "cat branch > $TMPDIR/forgebuild-branch" > $FORGEBUILDDIR/branch
chmod +x $FORGEBUILDDIR/branch
# 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 $TMPDIR ]; then rm -rf $TMPDIR; fi
}
# Simple repository
@test "hg: repository is cloned" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f $FORGEBUILDDIR/.time/README ]
}
@test "hg: first run triggers task" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f $TMPDIR/forgebuild-time ]
}
@test "hg: no update does not trigger task" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f $TMPDIR/forgebuild-time ]
TIME="$(cat $TMPDIR/forgebuild-time)"
$FORGEBUILD -b $FORGEBUILDDIR time
NEWTIME="$(cat $TMPDIR/forgebuild-time)"
[[ "$TIME" = "$NEWTIME" ]]
}
@test "hg: update triggers task" {
$FORGEBUILD -b $FORGEBUILDDIR time
[ -f $TMPDIR/forgebuild-time ]
TIME="$(cat $TMPDIR/forgebuild-time)"
cd $REPO
touch NEWFILE
hg add NEWFILE
hg commit -m "second commit"
$FORGEBUILD -b $FORGEBUILDDIR time
NEWTIME="$(cat $TMPDIR/forgebuild-time)"
[[ "$TIME" != "$NEWTIME" ]]
# Check that update has been propagated to the forgebuild copy of the repo
[ -f "$FORGEBUILDDIR"/.time/NEWFILE ]
}
@test "hg: can checkout to a specific branch/commit" {
echo "branch" > $FORGEBUILDDIR/branch.checkout
cd $REPO
hg branch branch
echo "branch" > branch
hg add branch
hg commit -m "new branch"
hg update default
$FORGEBUILD -b $FORGEBUILDDIR branch
# TODO: not sure why this test fails
[[ "$(cat $TMPDIR/forgebuild-branch)" = "branch" ]]
}
@test "hg: repository unavailable fails to trigger task" {
rm -Rf $REPO
! $FORGEBUILD -b $FORGEBUILDDIR time
[ ! -f $TMPDIR/forgebuild-time ]
}