eliminate race (loaded systems only?) that makes gl-conf look empty
[gitolite.git] / t / info-json.t
blob74fbdf4381d9fbc8aa3a5a9660872af80eea52b1
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::Test;
8 use JSON;
10 # the info command
11 # ----------------------------------------------------------------------
13 try 'plan 162';
15 try "## info";
17 confreset;confadd '
18 @t1 = t1
19 repo @t1
20 RW = u1
21 R = u2
22 repo t2
23 RW = u2
24 R = u1
25 repo t3
26 RW = u3
27 R = u4
29 repo foo/..*
30 C = u1
31 RW = CREATOR u3
34 try "ADMIN_PUSH info; !/FATAL/" or die text();
35 try "
36 /Initialized.*empty.*t1.git/
37 /Initialized.*empty.*t2.git/
38 /Initialized.*empty.*t3.git/
41 my $href; # semi-global (or at least file scoped lexical!)
43 # testing for info -json is a bit unusual. The actual tests are done within
44 # this test script itself, and we send Tsh just enough for it to decide if
45 # it's 'ok' or 'not ok' and print that.
47 try "glt info u1 -json; ok";
48 $href = from_json(text());
49 try "## u1 test_gs";
50 test_gs('u1');
51 try "## u1";
52 perm('foo/..*', 'r w C');
53 perm('testing', 'R W c');
54 perm('t1', 'R W c');
55 perm('t2', 'R w c');
56 perm('t3', 'r w c');
58 try "## u2";
59 try "glt info u2 -json; ok";
60 $href = from_json(text());
61 perm('foo/..*', 'r w c');
62 perm('testing', 'R W c');
63 perm('t1', 'R w c');
64 perm('t2', 'R W c');
65 perm('t3', 'r w c');
67 try "## u3";
68 try "glt info u3 -json; ok";
69 $href = from_json(text());
70 perm('foo/..*', 'R W c');
71 perm('testing', 'R W c');
72 perm('t1', 'r w c');
73 perm('t2', 'r w c');
74 perm('t3', 'R W c');
76 try "## u4";
77 try "glt info u4 -json; ok";
78 $href = from_json(text());
79 perm('foo/..*', 'r w c');
80 perm('testing', 'R W c');
81 perm('t1', 'r w c');
82 perm('t2', 'r w c');
83 perm('t3', 'R w c');
85 try "## u5";
86 try "glt info u5 -json; ok";
87 $href = from_json(text());
88 perm('foo/..*', 'r w c');
89 perm('testing', 'R W c');
90 perm('t1', 'r w c');
91 perm('t2', 'r w c');
92 perm('t3', 'r w c');
94 try "## u6";
95 try "glt info u6 -json; ok";
96 $href = from_json(text());
97 perm('foo/..*', 'r w c');
98 perm('testing', 'R W c');
99 perm('t1', 'r w c');
100 perm('t2', 'r w c');
101 perm('t3', 'r w c');
103 try "## ls-remote foo/one";
104 try "glt ls-remote u1 file:///foo/one; ok";
106 try "## u1";
107 try "glt info u1 -json; ok; !/creator..:/";
108 $href = from_json(text());
109 perm('foo/..*', 'r w C');
110 perm('foo/one', 'R W c');
111 test_creator('foo/one', 'u1', 'undef');
113 try "## u2";
114 try "glt info u2 -json; ok; !/creator..:/";
115 $href = from_json(text());
116 perm('foo/..*', 'r w c');
117 perm('foo/one', 'r w c');
118 test_creator('foo/one', 'u1', 'undef');
120 try "## u3";
121 try "glt info u3 -json; ok; !/creator..:/";
122 $href = from_json(text());
123 perm('foo/..*', 'R W c');
124 perm('foo/one', 'R W c');
125 test_creator('foo/one', 'u1', 'undef');
127 try("## with -lc now");
129 try "## u1";
130 try "glt info u1 -lc -json; ok";
131 $href = from_json(text());
132 perm('foo/..*', 'r w C');
133 perm('foo/one', 'R W c');
134 test_creator('foo/one', 'u1', 1);
136 try "## u2";
137 try "glt info u2 -lc -json; ok";
138 $href = from_json(text());
139 perm('foo/..*', 'r w c');
140 perm('foo/one', 'r w c');
141 test_creator('foo/one', 'u1', 'undef');
143 try "## u3";
144 try "glt info u3 -lc -json; ok";
145 $href = from_json(text());
146 perm('foo/..*', 'R W c');
147 perm('foo/one', 'R W c');
148 test_creator('foo/one', 'u1', 1);
150 # ----------------------------------------------------------------------
152 # test perms given repo and expected perms. (lowercase r/w/c means NOT
153 # expected, uppercase means expected)
154 sub perm {
155 my ($repo, $aa) = @_;
156 for my $aa1 (split ' ', $aa) {
157 my $exp = 1;
158 if ($aa1 =~ /[a-z]/) {
159 $exp = 'undef'; # we can't use 0, though I'd like to
160 $aa1 = uc($aa1);
162 my $perm = $href->{repos}{$repo}{perms}{$aa1} || 'undef';
163 try 'perl $_ = "' . $perm . '"; /' . $exp . '/';
167 # test versions in greeting string
168 sub test_gs {
169 my $glu = shift;
170 my $res = ( $href->{GL_USER} eq $glu ? 1 : 'undef' );
171 try 'perl $_ = "' . $res . '"; /1/';
172 $res = ( $href->{gitolite_version} =~ /^v3.[5-9]/ ? 1 : 'undef' );
173 try 'perl $_ = "' . $res . '"; /1/';
174 $res = ( $href->{git_version} =~ /^1.[6-9]|^2./ ? 1 : 'undef' );
175 try 'perl $_ = "' . $res . '"; /1/';
178 # test creator
179 sub test_creator {
180 my ($r, $c, $exp) = @_;
181 my $res = ( ($href->{repos}{$r}{creator} || '') eq $c ? 1 : 'undef' );
182 try 'perl $_ = "' . $res . '"; /' . $exp . '/';