Skip to content

Commit

Permalink
Modernize subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
ugexe committed Sep 8, 2022
1 parent b6edb79 commit b211bab
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions t/01-utils.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ plan 1;

use Net::HTTP::Utils;

subtest {
subtest 'Header case works [&hc]' => {
is hc("content-tyPE"), 'Content-Type', 'The basics';
is hc("X-XSS-Blah"), 'X-Xss-Blah', 'Not perfect, but good enough';
is hc("Transfer-encoding"), 'Transfer-Encoding';

}, 'Header case works [&hc]';
}

done-testing;
12 changes: 6 additions & 6 deletions t/02-url.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plan 3;

use Net::HTTP::URL;

subtest {
subtest '[name] valid absolute urls' => {
my %valid = %(
"http://httpbin.org"
=> %( :scheme<http>, :host<httpbin.org> ),
Expand Down Expand Up @@ -48,9 +48,9 @@ subtest {
is $url."$part"(), $expected;
}
}
}, '[name] valid absolute urls';
}

subtest {
subtest '[ipv4] valid absolute urls' => {
my %valid = %(
"http://192.168.0.1"
=> %( :scheme<http>, :host<192.168.0.1> ),
Expand Down Expand Up @@ -95,10 +95,10 @@ subtest {
is $url."$part"(), $expected;
}
}
}, '[ipv4] valid absolute urls';
}


subtest {
subtest '[ipv6] valid absolute urls' => {
my %valid = %(
"http://[2601:587:200:d159:972:cd3b:eb76:4eb5]"
=> %( :scheme<http>, :host<[2601:587:200:d159:972:cd3b:eb76:4eb5]> ),
Expand Down Expand Up @@ -143,6 +143,6 @@ subtest {
is $url."$part"(), $expected;
}
}
}, '[ipv6] valid absolute urls';
}

done-testing;
4 changes: 2 additions & 2 deletions t/03-request.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plan 1;
use Net::HTTP::Request;
use Net::HTTP::URL;

subtest {
subtest 'Basic: request header tests' => {
my $want-str = q{GET /search?x=1 HTTP/1.1}
~ "\r\n" ~ q{Host: google.com}
~ "\r\n" ~ q{User-Agent: raku-net-http}
Expand All @@ -28,6 +28,6 @@ subtest {
ok $_ ~~ any(@got);
}
}, 'Auto setting the host header';
}, 'Basic: request header tests';
}

done-testing;
4 changes: 2 additions & 2 deletions t/04-response.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plan 1;
use Net::HTTP::Response;
use Net::HTTP::URL;

subtest {
subtest 'Basic: response tests' => {
my $status-line = "HTTP/1.1 200 OK",
my %header = %(
:Access-Control-Allow-Credentials("true"),
Expand Down Expand Up @@ -42,6 +42,6 @@ subtest {
# is-deeply $response-from-args.header.hash, $response-from-buf.header.hash;

is $response-from-args.body.contents, $response-from-buf.body.contents;
}, 'Basic: response tests';
}

done-testing;
8 changes: 4 additions & 4 deletions xt/100-dialer.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ use Net::HTTP::URL;
use Net::HTTP::Request;


subtest {
subtest 'IO::Socket::INET selected and works' => {
my $url = Net::HTTP::URL.new("http://httpbin.org/ip");
my $method = 'GET';
my %header = :Host<httpbin.org>, :User-Agent("raku-net-http");
my $request = Net::HTTP::Request.new(:$url, :$method, :%header);
my $socket = Net::HTTP::Dialer.new.dial($request);

ok $socket ~~ IO::Socket::INET, 'IO::Socket::INET';
}, 'IO::Socket::INET selected and works';
}


if Net::HTTP::Dialer.?can-ssl {
subtest {
subtest 'IO::Socket::SSL selected and works' => {
my $url = Net::HTTP::URL.new("https://httpbin.org/ip");
my $method = 'GET';
my %header = :Host<httpbin.org>, :User-Agent("raku-net-http");
my $request = Net::HTTP::Request.new(:$url, :$method, :%header);
my $socket = Net::HTTP::Dialer.new.dial($request);

ok $socket ~~ ::('IO::Socket::SSL'), 'IO::Socket::SSL';
}, 'IO::Socket::SSL selected and works';
}
}
else {
ok 1, "Skip: Can't do SSL. Is IO::Socket::SSL available?";
Expand Down
16 changes: 8 additions & 8 deletions xt/500-transport.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Net::HTTP::Transport;
use Net::HTTP::URL;
use Net::HTTP::Request;

subtest {
subtest 'Transfer-Encoding: chunked [IO::Socket::INET]' => {
my $url = Net::HTTP::URL.new('http://jigsaw.w3.org/HTTP/ChunkedScript');
my $req = Net::HTTP::Request.new: :$url, :method<GET>,
header => :Connection<keep-alive>, :User-Agent<raku-net-http>;
Expand All @@ -16,9 +16,9 @@ subtest {

is $decoded.lines.grep(/^0/).elems, 1000;
is $decoded.chars, 72200;
}, 'Transfer-Encoding: chunked [IO::Socket::INET]';
}

subtest {
subtest 'Threads: start { $transport.round-trip($req) }' => {
my $url = Net::HTTP::URL.new('http://jigsaw.w3.org/HTTP/ChunkedScript');
my $req = Net::HTTP::Request.new: :$url, :method<GET>,
header => :Connection<keep-alive>, :User-Agent<raku-net-http>;
Expand All @@ -30,11 +30,11 @@ subtest {
for @responses -> $res {
is $res.body.decode.lines.grep(/^0/).elems, 1000;
}
}, 'Threads: start { $transport.round-trip($req) }';
}


if Net::HTTP::Dialer.?can-ssl {
subtest {
subtest 'Transfer-Encoding: chunked [IO::Socket::SSL]' => {
my $url = Net::HTTP::URL.new('https://jigsaw.w3.org/HTTP/ChunkedScript');
my $req = Net::HTTP::Request.new: :$url, :method<GET>,
header => :Connection<close>, :User-Agent<raku-net-http>;
Expand All @@ -45,14 +45,14 @@ if Net::HTTP::Dialer.?can-ssl {

is $decoded.lines.grep(/^0/).elems, 1000;
is $decoded.chars, 72200;
}, 'Transfer-Encoding: chunked [IO::Socket::SSL]';
}
}
else {
ok 1, "Skip: Can't do SSL. Is IO::Socket::SSL available?";
}

if Net::HTTP::Dialer.?can-ssl {
subtest {
subtest 'Threads: start { $transport.round-trip($req) } [IO::Socket::SSL]' => {
my $url = Net::HTTP::URL.new('https://jigsaw.w3.org/HTTP/ChunkedScript');
my $req = Net::HTTP::Request.new: :$url, :method<GET>,
header => :Connection<close>, :User-Agent<raku-net-http>;
Expand All @@ -64,7 +64,7 @@ if Net::HTTP::Dialer.?can-ssl {
for @responses -> $res {
is $res.body.decode.lines.grep(/^0/).elems, 1000;
}
}, 'Threads: start { $transport.round-trip($req) } [IO::Socket::SSL]';
}
}
else {
ok 1, "Skip: Can't do SSL. Is IO::Socket::SSL available?";
Expand Down
16 changes: 8 additions & 8 deletions xt/510-get.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ plan 4;

use Net::HTTP::GET;

subtest {
subtest 'Basic' => {
my $url = "http://httpbin.org";

my $response200 = Net::HTTP::GET($url ~ '/status/200');
is $response200.status-code, 200;

my $response400 = Net::HTTP::GET($url ~ '/status/400');
is $response400.status-code, "400";
}, "Basic";
}

subtest {
subtest 'Basic content' => {
my $url = "http://httpbin.org";

my $response = Net::HTTP::GET($url ~ '/encoding/utf8');
is $response.status-code, 200;
ok $response.content.contains('∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა');
}, "Basic content";
}

subtest {
subtest 'Redirect' => {
my $url = "http://httpbin.org/redirect/3";
my $response = Net::HTTP::GET($url);
is $response.status-code, 200, 'Status code of final redirect is 200';
Expand All @@ -33,19 +33,19 @@ subtest {
my $abs-url = "http://httpbin.org/absolute-redirect/1";
my $abs-response = Net::HTTP::GET($abs-url);
is $abs-response.status-code, 200, 'Status code of final absolute redirect is 200';
}, "Redirect";
}


if Net::HTTP::Dialer.?can-ssl {
subtest {
subtest 'Redirect with SSL' => {
my $https2https-url = "https://httpbin.org/absolute-redirect/2";
my $https2https-response = Net::HTTP::GET($https2https-url);
is $https2https-response.status-code, 200, 'Status code of final redirect is 200';

my $http2https-url = "http://github.com";
my $http2https-response = Net::HTTP::GET($http2https-url);
is $http2https-response.status-code, 200, 'Status code of final redirect is 200';
}, 'Redirect with SSL';
}
}
else {
ok 1, "Skip: Can't do SSL. Is IO::Socket::SSL available?";
Expand Down
4 changes: 2 additions & 2 deletions xt/520-post.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sub from-json($text) is export {
}
}

subtest {
subtest 'Basic POST' => {
my $url = "http://httpbin.org/post";
my $payload = "a=b&c=d&f=";
my $body = Buf.new($payload.ords);
Expand All @@ -25,6 +25,6 @@ subtest {

my $results = from-json($response.content(:force));
is $results<data>, $payload;
}, "Basic POST";
}

done-testing;
4 changes: 2 additions & 2 deletions xt/issues.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ diag('https://github.com/ugexe/Raku-Net--HTTP/issues/8 - thread interpolation wh
is +@failures, 0;
}

subtest {
subtest 'https://github.com/ugexe/Raku-Net--HTTP/issues/11 - Net::HTTP::Request::raw explodes on large (> 64kb) requests' => {
my $request = Net::HTTP::Request.new(
:url(Net::HTTP::URL.new("http://www.google.com/")),
:method<GET>,
Expand All @@ -32,6 +32,6 @@ subtest {
);

lives-ok { $request.raw().sink }
}, 'https://github.com/ugexe/Raku-Net--HTTP/issues/11 - Net::HTTP::Request::raw explodes on large (> 64kb) requests';
}

done-testing;

0 comments on commit b211bab

Please sign in to comment.