Test library for Gitano ======================= When running tests under yarn, for each scenario, we are provided with a temporary working directory called `$DATADIR` which is a fresh directory for each scenario being run. Within that base, we can set up any number of fake SSH keys, a fake Gitano instance, fake users, and use them to make clones, do pushes etc. Nearly all of the implementations rely on a tool in the testing directory called `gitano-test-tool` the path to which is available as `$GTT`. For ease of testing, the fake user who gets to "own" the Gitano instance will be called `testinstance` and the keyset which they get to use in order to access the repository will be called `adminkey`. This is important when it comes to cloning, pushing, etc. Managing the fake unix users ---------------------------- IMPLEMENTS GIVEN a unix user called ([a-z][a-z0-9]*) $GTT createunixuser $MATCH_1 IMPLEMENTS GIVEN ([a-z][a-z0-9]*) has keys called ([a-z][a-z0-9]*) $GTT createsshkey $MATCH_1 $MATCH_2 General instance management --------------------------- IMPLEMENTS GIVEN a standard instance $GTT createunixuser testinstance $GTT createsshkey testinstance adminkey $GTT setupstandard testinstance adminkey Repository access ----------------- IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? clones ([^ ]+) as ([^ ]+) $GTT cloneviassh $MATCH_1 $MATCH_2 "$MATCH_3" "$MATCH_4" Clone manipulation ------------------ IMPLEMENTS THEN ([a-z][a-z0-9]*) has a clone of ([^ ]+) $GTT cloneexists $MATCH_1 "$MATCH_2" IMPLEMENTS WHEN git pull happens in ([a-z][a-z0-9]*) ([^ ]+) cd "$($GTT clonelocation $MATCH_1 "$MATCH_2")" git pull IMPLEMENTS THEN ([a-z][a-z0-9]*) ([^ ]+) has a file called (.+) cd "$($GTT clonelocation $MATCH_1 "$MATCH_2")" test -r "$MATCH_3" IMPLEMENTS THEN ([a-z][a-z0-9]*) ([^ ]+) has no file called (.+) set -x cd "$($GTT clonelocation $MATCH_1 "$MATCH_2")" if test -r "$MATCH_3"; then false; else true; fi Admin repo manipulation ----------------------- IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? adds user ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) $GTT runcommand $MATCH_1 $MATCH_2 \ user add $MATCH_3 $MATCH_3@testinstance "$MATCH_3's real name" $GTT runcommand $MATCH_1 $MATCH_2 \ as $MATCH_3 sshkey add default < \ $($GTT pubkeyfilename $MATCH_4 $MATCH_5) IMPLEMENTS WHEN ([a-z][a-z0-9]*),? using ([a-z][a-z0-9]*),? deletes user ([a-z][a-z0-9]*) TOKEN=$($GTT runcommand $MATCH_1 $MATCH_2 user del $MATCH_3 2>&1 | $GTT findtoken) $GTT runcommand $MATCH_1 $MATCH_2 user del $MATCH_3 $TOKEN Generic utility methods ----------------------- IMPLEMENTS WHEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*) runs (.+) $GTT runcommand $MATCH_1 $MATCH_2 $MATCH_3 > $DATADIR/stdout 2> $DATADIR/stderr IMPLEMENTS WHEN ([a-z][a-z0-9]*) ([a-z][a-z0-9]*),? expecting failure,? runs (.+) if $GTT runcommand $MATCH_1 $MATCH_2 $MATCH_3 > $DATADIR/stdout 2> $DATADIR/stderr; then false fi IMPLEMENTS THEN ([^ ]+) contains (.+) grep -q "$MATCH_2" $DATADIR/"$MATCH_1" IMPLEMENTS THEN ([^ ]+) does not contain (.+) if grep -q "$MATCH_2" $DATADIR/"$MATCH_1"; then false; else true; fi IMPLEMENTS THEN ([^ ]+) is empty if grep -q . $DATADIR/"$MATCH_1"; then false; fi IMPLEMENTS THEN failure ensues cd $DATADIR echo "FIND:" find . echo "KEYS:" cat user-home-testinstance/.ssh/authorized_keys echo "OUT": cat stdout echo "ERR": cat stderr /bin/false