keeping the profs at Cambridge happy...
[gitolite.git] / t / easy.t
blobdcd6c1aac1586e6d29ae6484baa24c05edbcfec3
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # this is hardcoded; change it if needed
6 use lib "src/lib";
7 use Gitolite::Easy;
8 use Gitolite::Test;
9 # put this after ::Easy because it chdirs away from where you were and the
10 # 'use lib "src"', not being absolute, fails
12 # smoke tests for Easy.pm
13 # ----------------------------------------------------------------------
14 # for a change these are actual perl tests, so not much call for tsh here,
15 # although I still need the basic infrastructure for setting up the repos and
16 # I still can't intermix this with perl's Test.pm or Test::More etc
17 sub ok { (+shift) ? print "ok\n" : print "not ok\n"; }
18 sub nok { (+shift) ? print "not ok\n" : print "ok\n"; }
19 sub msg { return unless $ENV{D}; print STDERR "#" . +shift . "\n"; }
21 try "plan 98";
23 try "
24 cat $ENV{HOME}/.gitolite.rc
25 perl s/GIT_CONFIG_KEYS.*/GIT_CONFIG_KEYS => '.*',/
26 put $ENV{HOME}/.gitolite.rc
29 # basic push admin repo
30 confreset;confadd '
31 repo gitolite-admin
32 RW+ VREF/NAME/ = admin
33 RW+ VREF/NAME/u5/ = u5
35 repo aa
36 RW+ = u1
37 RW = u2
38 R = u4
40 config for.aa = 1
42 repo cc/..*
43 C = u4
44 RW+ = CREATOR u5
45 R = u6
47 config for.cc = 1
49 @oddguys = u1 u3 u5
50 @evensout = u2 u4 u6
52 repo cc/sub/..*
53 config sub.cc = 1
56 try "ADMIN_PUSH set1; !/FATAL/" or die text();
58 # valid_user() -- an internal function but still worth testing by itself first
59 eval { Gitolite::Easy::valid_user(); };
60 ok($@ =~ /FATAL.*GL_USER not set/);
61 $ENV{GL_USER} = "u2";
62 eval { Gitolite::Easy::valid_user(); };
63 nok($@ =~ /FATAL.*GL_USER not set/);
65 # is_admin
66 msg('is_admin');
67 $ENV{GL_USER} = "admin"; ok(is_admin());
68 $ENV{GL_USER} = "u5"; ok(is_admin());
69 $ENV{GL_USER} = "u2"; nok(is_admin());
71 # is_super_admin -- not sure how useful it is right now
72 msg('is_super_admin');
73 $ENV{GL_USER} = "admin"; ok( is_super_admin() );
74 $ENV{GL_USER} = "u5"; nok( is_super_admin() );
75 $ENV{GL_USER} = "u2"; nok( is_super_admin() );
77 # in_group
78 msg('in_group');
79 $ENV{GL_USER} = "u1"; ok( in_group('oddguys') ); nok( in_group('evensout') );
80 $ENV{GL_USER} = "u3"; ok( in_group('oddguys') ); nok( in_group('evensout') );
81 $ENV{GL_USER} = "u4"; nok( in_group('oddguys') ); ok( in_group('evensout') );
82 $ENV{GL_USER} = "u2"; nok( in_group('oddguys') ); ok( in_group('evensout') );
84 # owns
85 msg('owns');
86 try("glt ls-remote u4 cc/u4; /Initialized empty.*cc/u4/");
87 $ENV{GL_USER} = "u3"; nok( owns("cc/u3") ); nok( owns("cc/u4") );
88 $ENV{GL_USER} = "u4"; nok( owns("cc/u3") ); ok( owns("cc/u4") );
89 $ENV{GL_USER} = "u5"; nok( owns("cc/u3") ); nok( owns("cc/u4") );
91 # can_read
92 msg('can_read');
93 $ENV{GL_USER} = "u1"; ok(can_read("aa"));
94 $ENV{GL_USER} = "u2"; ok(can_read("aa"));
95 $ENV{GL_USER} = "u3"; nok(can_read("aa"));
96 $ENV{GL_USER} = "u4"; ok(can_read("aa"));
98 $ENV{GL_USER} = "u1"; nok(can_read("bb"));
99 $ENV{GL_USER} = "u2"; nok(can_read("bb"));
100 $ENV{GL_USER} = "u3"; nok(can_read("bb"));
101 $ENV{GL_USER} = "u4"; nok(can_read("bb"));
103 $ENV{GL_USER} = "u3"; nok(can_read("cc/u3"));
104 $ENV{GL_USER} = "u4"; nok(can_read("cc/u3"));
105 $ENV{GL_USER} = "u5"; nok(can_read("cc/u3"));
106 $ENV{GL_USER} = "u6"; nok(can_read("cc/u3"));
108 $ENV{GL_USER} = "u3"; nok(can_read("cc/u4"));
109 $ENV{GL_USER} = "u4"; ok(can_read("cc/u4"));
110 $ENV{GL_USER} = "u5"; ok(can_read("cc/u4"));
111 $ENV{GL_USER} = "u6"; ok(can_read("cc/u4"));
113 # can_write
114 msg('can_write');
115 $ENV{GL_USER} = "u1"; ok(can_write("aa"));
116 $ENV{GL_USER} = "u2"; ok(can_write("aa"));
117 $ENV{GL_USER} = "u3"; nok(can_write("aa"));
118 $ENV{GL_USER} = "u4"; nok(can_write("aa"));
120 $ENV{GL_USER} = "u1"; ok(can_write("aa", "+"));
121 $ENV{GL_USER} = "u2"; nok(can_write("aa", "+"));
122 $ENV{GL_USER} = "u3"; nok(can_write("aa", "+"));
123 $ENV{GL_USER} = "u4"; nok(can_write("aa", "+"));
125 $ENV{GL_USER} = "u1"; nok(can_write("bb"));
126 $ENV{GL_USER} = "u2"; nok(can_write("bb"));
127 $ENV{GL_USER} = "u3"; nok(can_write("bb"));
128 $ENV{GL_USER} = "u4"; nok(can_write("bb"));
130 $ENV{GL_USER} = "u3"; nok(can_write("cc/u3"));
131 $ENV{GL_USER} = "u4"; nok(can_write("cc/u3"));
132 $ENV{GL_USER} = "u5"; nok(can_write("cc/u3"));
133 $ENV{GL_USER} = "u6"; nok(can_write("cc/u3"));
135 $ENV{GL_USER} = "u3"; nok(can_write("cc/u4"));
136 $ENV{GL_USER} = "u4"; ok(can_write("cc/u4"));
137 $ENV{GL_USER} = "u5"; ok(can_write("cc/u4"));
138 $ENV{GL_USER} = "u6"; nok(can_write("cc/u4"));
140 $ENV{GL_USER} = "u3"; nok(can_write("cc/u4", "+"));
141 $ENV{GL_USER} = "u4"; ok(can_write("cc/u4", "+"));
142 $ENV{GL_USER} = "u5"; ok(can_write("cc/u4", "+"));
143 $ENV{GL_USER} = "u6"; nok(can_write("cc/u4", "+"));
145 # config
146 try("glt ls-remote u4 cc/sub/one; /Initialized empty.*cc/sub/one/");
147 try("glt ls-remote u4 cc/two; /Initialized empty.*cc/two/");
148 ok(1);
149 my @a;
150 @a = config("aa", "fo..aa"); ok($a[0] eq 'for.aa' and $a[1] eq '1');
151 @a = config("aa", "for.aa"); ok($a[0] eq 'for.aa' and $a[1] eq '1');
152 @a = config("aa", "fo\\..aa"); ok(scalar(@a) == 0);
154 @a = config("aa", "fo..cc"); ok(scalar(@a) == 0);
155 @a = config("aa", "for.cc"); ok(scalar(@a) == 0);
156 @a = config("aa", "fo\\..cc"); ok(scalar(@a) == 0);
158 @a = config("bb", "fo..aa"); ok(scalar(@a) == 0);
159 @a = config("bb", "for.aa"); ok(scalar(@a) == 0);
160 @a = config("bb", "fo\\..aa"); ok(scalar(@a) == 0);
162 @a = config("cc/u4", "fo..aa"); ok(scalar(@a) == 0);
163 @a = config("cc/u4", "for.aa"); ok(scalar(@a) == 0);
164 @a = config("cc/u4", "fo\\..aa"); ok(scalar(@a) == 0);
166 @a = config("cc/u4", "fo..cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
167 @a = config("cc/u4", "for.cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
168 @a = config("cc/u4", "fo\\..cc"); ok(scalar(@a) == 0);
170 @a = config("cc/two", "fo..cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
171 @a = config("cc/two", "for.cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
172 @a = config("cc/two", "fo\\..cc"); ok(scalar(@a) == 0);
174 @a = config("cc/sub/one", "fo..cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
175 @a = config("cc/sub/one", "for.cc"); ok($a[0] eq 'for.cc' and $a[1] eq '1');
176 @a = config("cc/sub/one", "fo\\..cc"); ok(scalar(@a) == 0);
178 @a = config("cc/sub/one", "su..cc"); ok($a[0] eq 'sub.cc' and $a[1] eq '1');
179 @a = config("cc/sub/one", "sub.cc"); ok($a[0] eq 'sub.cc' and $a[1] eq '1');
180 @a = config("cc/sub/one", "su\\..cc"); ok(scalar(@a) == 0);