1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<!-- -*- markdown -*- -->
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
|