This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
/
test.pl
159 lines (124 loc) · 2.81 KB
/
test.pl
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use Cwd;
use Config;
$cur_dir = cwd();
$failed = 0;
$num_tests = 2;
die "Must be in build directory\n" unless -d 'blib';
$ENV{MINIVEND_ROOT} = "$cur_dir/blib";
$ENV{MINIVEND_BADPOSIX} = 1;
open(CONFIG, ">$ENV{MINIVEND_ROOT}/minivend.cfg")
or die "open: $!\n";
print CONFIG <<EOF;
Catalog test $ENV{MINIVEND_ROOT} /test
EOF
open(CONFIG, ">$ENV{MINIVEND_ROOT}/catalog.cfg")
or die "open: $!\n";
print CONFIG <<EOF;
MailOrderTo mikeh\@minivend.com
VendURL http:/test
SecureURL http:/test
EOF
mkdir ("$ENV{MINIVEND_ROOT}/etc", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/pages", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/products", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/session", 0777);
if( $ENV{PERL5LIB} ) {
$ENV{PERL5LIB} .= ":$cur_dir/extra";
}
else {
$ENV{PERL5LIB} = "$cur_dir/extra";
}
open(CONFIG, ">$ENV{MINIVEND_ROOT}/products/products.asc")
or die "open: $!\n";
print CONFIG <<EOF;
sku description price
test test product 1
EOF
open(CONFIG, ">$ENV{MINIVEND_ROOT}/pages/catalog.html")
or die "open: $!\n";
for(1 .. 100) {
print CONFIG <<EOF;
test succeeded test succeeded
EOF
}
close CONFIG;
print "server.......";
if ( system "$Config{'perlpath'} dist/bin/minivend -serve -u >/dev/null" ) {
print "not ok 1\n";
}
else {
print "ok 1\n";
}
sleep 1;
open(PID, "$ENV{MINIVEND_ROOT}/etc/minivend.pid") or die "read PID file: $!\n";
$pid = <PID>;
$pid =~ s/\D+//g;
use Socket;
my $LINK_FILE = "$ENV{MINIVEND_ROOT}/etc/socket";
my $LINK_TIMEOUT = 5;
my $ERROR_ACTION = "-none";
$ENV{SCRIPT_NAME} = "/test";
$ENV{PATH_INFO} = "/catalog";
$ENV{REMOTE_ADDR} = "TEST";
$ENV{REQUEST_METHOD} = "GET";
sub send_arguments {
my $count = @ARGV;
my $val = "arg $count\n";
for(@ARGV) {
$val .= length($_);
$val .= " $_\n";
}
return $val;
}
sub send_environment () {
my (@tmp) = keys %ENV;
my $count = @tmp;
my ($str);
my $val = "env $count\n";
for(@tmp) {
$str = "$_=$ENV{$_}";
$val .= length($str);
$val .= " $str\n";
}
return $val;
}
$SIG{PIPE} = sub { die_page("signal"); };
$SIG{ALRM} = sub { server_not_running(); exit 1; };
alarm $LINK_TIMEOUT;
print "socket link..";
socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!\n";
my $ok;
do {
$ok = connect(SOCK, sockaddr_un($LINK_FILE));
} while ( ! defined $ok and $! =~ /interrupt|such file or dir/i);
my $undef = ! defined $ok;
die "ok=$ok def: $undef connect: $!\n" if ! $ok;
select SOCK;
$| = 1;
select STDOUT;
print SOCK send_arguments();
print SOCK send_environment();
print SOCK "end\n";
while(<SOCK>) {
$result .= $_;
}
close (SOCK) or die "close: $!\n";
if(length($result) > 500 and $result =~ /test succeeded/i) {
print "ok 2\n";
}
else {
print "not ok 2\n";
$failed++;
}
print "$num_tests tests run";
if($failed) {
print " -- $failed/$numtests failed.\n";
exit 1;
}
else {
print ", all tests successful.\n";
exit 0;
}
END {
kill 'KILL', $pid;
}