More tests on errors (#595)

This commit is contained in:
Xavier Guimard 2017-03-22 18:11:45 +00:00
parent e8c2925a3f
commit 5cd25e3df5
2 changed files with 15 additions and 5 deletions

View File

@ -26,7 +26,7 @@ SKIP: {
$client = iniCmb('[Dm] and [DB]');
expectCookie( try('rtyler') );
expectReject( try('dwho') );
expectReject( try('dwho'), 5 );
$client = iniCmb('if($env->{HTTP_X} eq "dwho") then [Dm] else [DB]');
expectCookie( try('dwho') );
@ -37,7 +37,7 @@ SKIP: {
);
expectCookie( try('rtyler') );
expectCookie( try('dvador') );
expectReject( try('dwho') );
expectReject( try('dwho'), 5 );
}
count($mainTests);
clean_sessions();

View File

@ -26,7 +26,7 @@ sub count {
sub main::explain {
my ( $get, $ref ) = @_;
$get = Dumper($get) if ( ref $get );
print STDERR "Expect $ref, get $get\n";
diag("Expect $ref, get $get\n");
}
sub clean_sessions {
@ -160,9 +160,19 @@ sub expectBadRequest {
}
sub expectReject {
my ($res) = @_;
my ( $res, $code ) = @_;
ok( $res->[0] == 401, ' Response is 401' ) or explain( $res->[0], 401 );
count(1);
eval { $res = JSON::from_json( $res->[2]->[0] ) };
ok( not($@), 'Content is JSON' )
or explain( $res->[2]->[0], 'JSON content' );
if ( defined $code ) {
ok( $res->{error} == $code, "Error code is $code" )
or explain( $res->{error}, $code );
}
else {
pass("Error code is $code");
}
count(3);
}
sub expectCookie {