Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 295 lines (228 sloc) 5.213 kB
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
1 use Cwd;
2 use Config;
2666536 @perusionmike Changed test.pl to use Errno.pm to derive socket test error messages.
perusionmike authored
3 use Errno;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
4
5 $cur_dir = cwd();
6 $failed = 0;
7
8 die "Must be in build directory\n" unless -d 'blib';
9 die "No tests defined for Windows\n" if $^O =~ /win32/i;
10
11 $ENV{MINIVEND_ROOT} = "$cur_dir/blib";
12 $ENV{MINIVEND_PORT} = 8786 unless defined $ENV{MINIVEND_PORT};
13
d4330cc @perusionmike Change minivend.cfg to interchange.cfg, etc.
perusionmike authored
14 open(CONFIG, ">$ENV{MINIVEND_ROOT}/interchange.cfg")
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
15 or die "open: $!\n";
16
17 print CONFIG <<EOF;
18 Catalog test $ENV{MINIVEND_ROOT} /test
19 TcpMap $ENV{MINIVEND_PORT} -
20 EOF
21
22 open(CONFIG, ">$ENV{MINIVEND_ROOT}/catalog.cfg")
23 or die "open: $!\n";
24
25 print CONFIG <<EOF;
d6dc450 @perusionmike Changed Interchange name all over, minor exceptions being mvfaq.pod and
perusionmike authored
26 MailOrderTo info\@akopia.com
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
27 VendURL http:/test
28 SecureURL http:/test
29 Database products products.asc DEFAULT
30 EOF
31
32 mkdir ("$ENV{MINIVEND_ROOT}/etc", 0777);
33 mkdir ("$ENV{MINIVEND_ROOT}/pages", 0777);
34 mkdir ("$ENV{MINIVEND_ROOT}/products", 0777);
35 mkdir ("$ENV{MINIVEND_ROOT}/session", 0777);
36 if( $ENV{PERL5LIB} ) {
37 $ENV{PERL5LIB} .= ":$cur_dir/extra:$cur_dir/blib/lib";
38 }
39 else {
40 $ENV{PERL5LIB} = "$cur_dir/extra:$cur_dir/blib/lib";
41 }
42
43 my $testnum = 1;
44
45 open(CONFIG, ">$ENV{MINIVEND_ROOT}/products/products.asc")
46 or die "open: $!\n";
47
48 print CONFIG <<EOF;
49 sku description price
50 test test product 1
51 EOF
52
53 open(CONFIG, ">$ENV{MINIVEND_ROOT}/pages/catalog.html")
54 or die "open: $!\n";
55
56 for(1 .. 100) {
57 print CONFIG <<EOF;
58 test succeeded test succeeded
59 EOF
60 }
61
62 close CONFIG;
63
64 $| = 1;
65
66 print "server/unixmode.......";
ca460c8 s:blib/script/minivend:blib/script/interchange:
Eric Zarko authored
67 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -u} ) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
68 print "not ok $testnum\n";
69 $failed++;
70 }
71 else {
72 print "ok $testnum\n";
73 }
74 $testnum++;
75
76 print "server/startup........";
77 for(1 .. 5) {
d4330cc @perusionmike Change minivend.cfg to interchange.cfg, etc.
perusionmike authored
78 open(PID, "$ENV{MINIVEND_ROOT}/etc/interchange.pid") or sleep $_, next;
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
79 $pid = <PID>;
80 $pid =~ s/\D+//g;
81 last;
82 }
83
84 for(1 .. 5) {
85 unless (-e "$ENV{MINIVEND_ROOT}/etc/socket") {
86 system "ls -l $ENV{MINIVEND_ROOT}/*";
87 sleep $_;
88 next;
89 }
90 $LINK_FILE = "$ENV{MINIVEND_ROOT}/etc/socket";
91 last;
92 }
93
94 if(! $pid or ! $LINK_FILE) {
95 print "not ok $testnum\n";
96 $failed++;
97 }
98 else {
99 print "ok $testnum\n";
100 }
101 $testnum++;
102
103 use Socket;
104 my $LINK_HOST = 'localhost';
105 my $LINK_PORT = $ENV{MINIVEND_PORT};
106 my $LINK_TIMEOUT = 15;
107 my $ERROR_ACTION = "-none";
108
109 $ENV{SCRIPT_NAME} = "/test";
110 $ENV{PATH_INFO} = "/catalog";
111 $ENV{REMOTE_ADDR} = "TEST";
112 $ENV{REQUEST_METHOD} = "GET";
113
114 sub send_arguments {
115
116 my $count = @ARGV;
117 my $val = "arg $count\n";
118 for(@ARGV) {
119 $val .= length($_);
120 $val .= " $_\n";
121 }
122 return $val;
123 }
124
125 sub send_environment () {
126 my (@tmp) = keys %ENV;
127 my $count = @tmp;
128 my ($str);
129 my $val = "env $count\n";
130 for(@tmp) {
131 $str = "$_=$ENV{$_}";
132 $val .= length($str);
133 $val .= " $str\n";
134 }
135 return $val;
136 }
137
138 $SIG{PIPE} = sub { die("signal"); };
139 $SIG{ALRM} = sub { die("not communicating with server\n"); exit 1; };
140
141
142
143 print "link/unixmode.........";
144 eval {
145 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!\n";
146
147 my $ok;
148 do {
149 $ok = connect(SOCK, sockaddr_un($LINK_FILE));
2666536 @perusionmike Changed test.pl to use Errno.pm to derive socket test error messages.
perusionmike authored
150 } while ( ! defined $ok and $!{EINTR} || $!{ENOENT});
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
151
152 my $undef = ! defined $ok;
153 die "ok=$ok def: $undef connect: $!\n" if ! $ok;
154
155 select SOCK;
156 $| = 1;
157 select STDOUT;
158
159 print SOCK send_arguments();
160 print SOCK send_environment();
161 print SOCK "end\n";
162
163
164 while(<SOCK>) {
165 $result .= $_;
166 }
167
168 close (SOCK) or die "close: $!\n";
169
170 };
171
172 if(length($result) > 500 and $result =~ /test succeeded/i) {
173 print "ok $testnum\n";
174 }
175 else {
176 print "not ok $testnum";
177 print " ($@)" if $@;
178 print "\n";
179 print <<EOF;
180
181 # When the above test fails, it may be due to your ISP or some other
182 # mechanism blocking port 8786.
183
184 EOF
185 $failed++;
186 }
187 $testnum++;
188
189 print "server/inetmode.......";
ca460c8 s:blib/script/minivend:blib/script/interchange:
Eric Zarko authored
190 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -i} ) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
191 print "not ok $testnum\n";
192 $failed++;
193 }
194 else {
195 print "ok $testnum\n";
196 }
197 $testnum++;
198
199 alarm 0;
200 alarm $LINK_TIMEOUT;
201
202 $result = '';
203
204 print "link/inetmode.........";
205 eval {
206 $remote = $LINK_HOST;
207 $port = $LINK_PORT;
208
209 if ($port =~ /\D/) { $port = getservbyname($port, 'tcp'); }
210
211 die("no port") unless $port;
212
213 $iaddr = inet_aton($remote);
214 $paddr = sockaddr_in($port,$iaddr);
215
216 $proto = getprotobyname('tcp');
217
218 socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";
219
220 my $ok;
221
222 do {
223 $ok = connect(SOCK, $paddr);
2666536 @perusionmike Changed test.pl to use Errno.pm to derive socket test error messages.
perusionmike authored
224 } while ( ! defined $ok and $!{EINTR});
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
225
226 my $undef = ! defined $ok;
227 die "ok=$ok def: $undef connect: $!\n" if ! $ok;
228
229 select SOCK;
230 $| = 1;
231 select STDOUT;
232
233 print SOCK send_arguments();
234 print SOCK send_environment();
235 print SOCK "end\n";
236
237
238 while(<SOCK>) {
239 $result .= $_;
240 }
241
242 close (SOCK) or die "close: $!\n";
243
244 };
245
246 alarm 0;
247
248 if(length($result) > 500 and $result =~ /test succeeded/i) {
249 print "ok $testnum\n";
250 }
251 else {
252 print "not ok $testnum\n";
253 $failed++;
254 }
255 $testnum++;
256
257 print "server/control........";
ca460c8 s:blib/script/minivend:blib/script/interchange:
Eric Zarko authored
258 if ( system qq{$Config{'perlpath'} blib/script/interchange -q -stop} ) {
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
259 print "not ok $testnum\n";
260 $failed++;
261 }
262
263 my $pid_there;
264
265 for(1 .. 5) {
d4330cc @perusionmike Change minivend.cfg to interchange.cfg, etc.
perusionmike authored
266 $pid_there = -f 'blib/etc/interchange.pid';
5550c3a @perusionmike Initial import of changed Challenger with UI instead of Minimate.
perusionmike authored
267 last unless $pid_there;
268 sleep 1;
269 }
270
271 if ($pid_there) {
272 print "not ok $testnum\n";
273 $failed++;
274 }
275 else {
276 print "ok $testnum\n";
277 }
278 $testnum++;
279
280
281 $testnum--;
282 print "$testnum tests run";
283 if($failed) {
284 print " -- $failed/$testnum failed.\n";
285 exit 1;
286 }
287 else {
288 print ", all tests successful.\n";
289 exit 0;
290 }
291
292 END {
293 kill 'KILL', $pid if $pid;
294 }
Something went wrong with that request. Please try again.