1193326Sed#!perl
2193326Sed
3353358Sdimuse strict;
4353358Sdimuse warnings;
5353358Sdim
6193326Seduse Test::More tests => 4;
7193326Seduse lib 't';
8193326Seduse SimpleCookieJar;
9280031Sdimuse BrokenCookieJar;
10280031Sdimuse HTTP::Tiny;
11193326Sed
12226633Sdim### a couple tests to ensure that:
13249423Sdim###  * by default there is no cookie jar defined
14193326Sed###  * the correct cookie jar is returned when specified
15193326Sed###  * error when cookie jar does not support the add and cookie_header methods
16261991Sdim
17261991Sdim
18193326Sedmy $default = undef;
19193326Sedmy $jar = SimpleCookieJar->new();
20249423Sdimmy $mug = BrokenCookieJar->new();
21193326Sedmy $dog = BrokenCookieJar2->new();
22249423Sdim
23249423Sdim{
24249423Sdim    my $ua = HTTP::Tiny->new();
25193326Sed    is $ua->cookie_jar, $default, 'default cookie jar is as expected';
26226633Sdim}
27193326Sed
28193326Sed{
29193326Sed    my $ua = HTTP::Tiny->new(cookie_jar => $jar);
30193326Sed    is $ua->cookie_jar, $jar, 'cookie_jar is as expected';
31193326Sed}
32
33{
34    my $ua = eval { HTTP::Tiny->new(cookie_jar => $mug) };
35    my $err = $@;
36    like( $err, qr/must provide .* 'add' method/
37	  => 'invalid jar does not support add method' );
38    
39    $ua = eval { HTTP::Tiny->new(cookie_jar => $dog) };
40    $err = $@;
41    like( $err, qr/must provide .* 'cookie_header' method/
42	  => 'invalid jar does not support cookie_header method' );
43}
44