add file.custom-handler tests

This commit is contained in:
Ichito Nagata 2017-09-06 15:33:10 +09:00
parent cb1c5134ca
commit a5c3c68a7d
2 changed files with 82 additions and 44 deletions

82
t/50file-custom-handler.t Normal file
View File

@ -0,0 +1,82 @@
use strict;
use warnings;
use Test::More;
use t::Util;
plan skip_all => 'curl not found'
unless prog_exists('curl');
subtest 'cgi file' => sub {
eval q{use CGI; 1}
or plan skip_all => 'CGI.pm not found';
# spawn h2o
my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: .cgi
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
hosts:
default:
paths:
/robots.txt:
file.file: @{[DOC_ROOT]}/hello.cgi
EOT
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/robots.txt?name=Tobor`;
is $resp, "Hello Tobor";
});
};
subtest 'cgi file with no extension' => sub {
eval q{use CGI; 1}
or plan skip_all => 'CGI.pm not found';
# spawn h2o
my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: default
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
hosts:
default:
paths:
/robots.txt:
file.file: @{[DOC_ROOT]}/noextcgi
EOT
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/robots.txt?name=Tobor`;
is $resp, "Hello Tobor";
});
};
subtest 'directory containing cgi files' => sub {
eval q{use CGI; 1}
or plan skip_all => 'CGI.pm not found';
# spawn h2o
my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: ["default", ".cgi"]
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
hosts:
default:
paths:
/:
file.dir: @{[DOC_ROOT]}
EOT
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/hello.cgi?name=Tobor`;
is $resp, "Hello Tobor";
});
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/noextcgi?name=Tobor`;
is $resp, "Hello Tobor";
});
};
done_testing;

View File

@ -29,48 +29,4 @@ EOT
});
};
subtest 'dynamic' => sub {
eval q{use CGI; 1}
or plan skip_all => 'CGI.pm not found';
# spawn h2o
my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: .cgi
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
hosts:
default:
paths:
/robots.txt:
file.file: @{[DOC_ROOT]}/hello.cgi
EOT
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/robots.txt?name=Tobor`;
is $resp, "Hello Tobor";
});
};
subtest 'dynamic with default type' => sub {
eval q{use CGI; 1}
or plan skip_all => 'CGI.pm not found';
# spawn h2o
my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: default
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
hosts:
default:
paths:
/robots.txt:
file.file: @{[DOC_ROOT]}/noextcgi
EOT
run_with_curl($server, sub {
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/robots.txt?name=Tobor`;
is $resp, "Hello Tobor";
});
};
done_testing;