Archive-Har

 view release on metacpan or  search on metacpan

t/pingdom.t  view on Meta::CPAN

#!perl -T

use Test::More tests => 64;
use Archive::Har();
use JSON();

my $har = Archive::Har->new();

my $pingdom_string = '{"log":{"version":"1.2","creator":{"name":"Pingdom Tools","version":"","comment":"Test the load time of a web page at http://tools.pingdom.com/fpt"},"pages":[{"startedDateTime":"2012-03-23T01:22:05.820Z","id":"https://duckduckgo...

ok($har->string($pingdom_string), "Successfully read pingdom har archive for https://duckduckgo.com/?q=http+archive+specification");
ok($har->version() eq '1.2', "INPUT: Pingdom produces a version 1.2 http archive");
ok($har->creator()->name() eq 'Pingdom Tools', "INPUT: Pingdom's creator name is 'Pingdom Tools'");
ok($har->creator()->version() eq '', "INPUT: Pingdom's creator version is the empty string");
ok($har->creator()->comment() eq 'Test the load time of a web page at http://tools.pingdom.com/fpt', "INPUT: Pingdom's creator comment is advertising for Pingdom");
ok(scalar $har->pages() == 1, "INPUT: Pingdom's archive contains 1 page");
my ($firstPage) = $har->pages();
ok($firstPage->started_date_time() eq '2012-03-23T01:22:05.820Z', "INPUT: Pingdom's archive page has a startedDateTime of '2012-03-23T01:22:05.820Z'");
ok($firstPage->id() eq 'https://duckduckgo.com/?q=http+archive+specification', "INPUT: Pingdom's archive page has an id of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($firstPage->title() eq '', "INPUT: Pingdom's archive page has an empty string as the title");
ok($firstPage->page_timings()->on_content_load(-1) == 333, "INPUT: Pingdom's archive page has an onContentLoad of 333");
ok(not(defined $firstPage->page_timings()->on_content_load(undef)), "INPUT: Pingdom's archive page has an onContentLoad that is not defined (after being set to -1)");
ok(not(defined $firstPage->page_timings()->on_content_load(333)), "INPUT: Pingdom's archive page has an onContentLoad that is not defined (after being set to undef");
ok($firstPage->page_timings()->on_load(-1) == 372, "INPUT: Pingdom's archive page has an onLoad of 372");
ok(not(defined $firstPage->page_timings()->on_load(undef)), "INPUT: Pingdom's archive page has an onLoad that is not defined (after being set to -1)");
ok(not(defined $firstPage->page_timings()->on_load(372)), "INPUT: Pingdom's archive page has an onLoad that is not defined (after being set to undef)");
ok(scalar $har->entries() == 46, "INPUT: Pingdom's archive contains 46 entries");
my ($firstEntry) = $har->entries();
ok($firstEntry->pageref() eq 'https://duckduckgo.com/?q=http+archive+specification', "INPUT: Pingdom's archive first entry has a pageref of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($firstEntry->started_date_time() eq '2012-03-23T01:22:05.820Z', "INPUT: Pingdom's archive first entry has a startedDateTime of '2012-03-23T01:22:05.820Z'");
ok($firstEntry->time() == 173, "INPUT: Pingdom's archive first entry has a time of 173");
ok($firstEntry->request()->method() eq 'GET', "INPUT: Pingdom's archive first entry request has a method of 'GET'");
ok($firstEntry->request()->url() eq 'https://duckduckgo.com/?q=http+archive+specification', "INPUT: Pingdom's archive first entry request has a url of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($firstEntry->request()->http_version() eq 'HTTP/1.1', "INPUT: Pingdom's archive first entry request has a version of 'HTTP/1.1'");
ok(scalar $firstEntry->request()->cookies() == 0, "INPUT: Pingdom's archive first entry request has an empty cookie list");
ok(scalar $firstEntry->request()->headers() == 9, "INPUT: Pingdom's archive first entry request has 9 headers");
ok(scalar $firstEntry->timings()->blocked() == 0, "INPUT: Pingdom's archive first entry timings has a blocked value of 0");
ok(not(defined $firstEntry->timings()->dns()), "INPUT: Pingdom's archive first entry timings does not have a defined value for dns");
ok(scalar $firstEntry->timings()->connect() == 125, "INPUT: Pingdom's archive first entry timings has a connect value of 125");
ok(scalar $firstEntry->timings()->send() == 0, "INPUT: Pingdom's archive first entry timings has a send value of 0");
ok(scalar $firstEntry->timings()->wait() == 28, "INPUT: Pingdom's archive first entry timings has a wait value of 28");
ok(scalar $firstEntry->timings()->receive() == 1, "INPUT: Pingdom's archive first entry timings has a receive value of 1");
ok(scalar $firstEntry->timings()->ssl() == 19, "INPUT: Pingdom's archive first entry timings has a ssl value of 19");
$firstEntry->timings()->ssl(20);
ok($firstEntry->time() == 174, "INPUT: Pingdom's archive first entry has a time of 174 (after \$entry->timings()->ssl() was set to 20");
$firstEntry->timings()->ssl(19);
ok($firstEntry->time() == 173, "INPUT: Pingdom's archive first entry has a time of 173 (after \$entry->timings()->ssl() was reset to 19");
my $pingdom_ref = JSON::decode_json("$har");
ok($pingdom_ref->{log}->{version} eq '1.2', "OUTPUT: Pingdom produces a version 1.2 http archive");
ok($pingdom_ref->{log}->{creator}->{name} eq 'Pingdom Tools', "OUTPUT: Pingdom's creator name is 'Pingdom Tools'");
ok($pingdom_ref->{log}->{creator}->{version} eq '', "OUTPUT: Pingdom's creator version is the empty string");
ok($pingdom_ref->{log}->{creator}->{comment} eq 'Test the load time of a web page at http://tools.pingdom.com/fpt', "OUTPUT: Pingdom's creator comment is advertising for Pingdom");
ok(scalar @{$pingdom_ref->{log}->{pages}} == 1, "OUTPUT: Pingdom's archive contains 1 page");
ok($pingdom_ref->{log}->{pages}->[0]->{startedDateTime} eq '2012-03-23T01:22:05.820Z', "OUTPUT: Pingdom's archive page has a startedDateTime of '2012-03-23T01:22:05.820Z'");
ok($pingdom_ref->{log}->{pages}->[0]->{id} eq 'https://duckduckgo.com/?q=http+archive+specification', "OUTPUT: Pingdom's archive page has an id of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($pingdom_ref->{log}->{pages}->[0]->{title} eq '', "OUTPUT: Pingdom's archive page has an empty string as the title");
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onContentLoad} == 333, "OUTPUT: Pingdom's archive page has an onContentLoad of 333");
$firstPage->page_timings()->on_content_load(undef);
$pingdom_ref = $har->hashref();
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onContentLoad} == -1, "OUTPUT: Pingdom's archive page has an onContentLoad of -1 after being set to undef");
$firstPage->page_timings()->on_content_load('-1');
$pingdom_ref = $har->hashref();
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onContentLoad} == -1, "OUTPUT: Pingdom's archive page has an onContentLoad of -1 after being set to '-1'");
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onLoad} == 372, "OUTPUT: Pingdom's archive page has an onLoad of 372");
$firstPage->page_timings()->on_load(undef);
$pingdom_ref = $har->hashref();
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onContentLoad} == -1, "OUTPUT: Pingdom's archive page has an onContentLoad of -1 after being set to '-1'");
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onLoad} == -1, "OUTPUT: Pingdom's archive page has an onLoad of -1 after being set to undef");
$firstPage->page_timings()->on_load("-1");
$pingdom_ref = $har->hashref();
ok($pingdom_ref->{log}->{pages}->[0]->{pageTimings}->{onLoad} == -1, "OUTPUT: Pingdom's archive page has an onLoad of -1 after being set to '-1'");
ok(scalar @{$pingdom_ref->{log}->{entries}} == 46, "OUTPUT: Pingdom's archive contains 46 entries");
ok($pingdom_ref->{log}->{entries}->[0]->{pageref} eq 'https://duckduckgo.com/?q=http+archive+specification', "OUTPUT: Pingdom's archive first entry has a pageref of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($pingdom_ref->{log}->{entries}->[0]->{startedDateTime} eq '2012-03-23T01:22:05.820Z', "OUTPUT: Pingdom's archive first entry has a startedDateTime of '2012-03-23T01:22:05.820Z'");
ok($pingdom_ref->{log}->{entries}->[0]->{time} == 173, "OUTPUT: Pingdom's archive first entry has a time of 173");
ok($pingdom_ref->{log}->{entries}->[0]->{request}->{method} eq 'GET', "OUTPUT: Pingdom's archive first entry request has a method of 'GET'");
ok($pingdom_ref->{log}->{entries}->[0]->{request}->{url} eq 'https://duckduckgo.com/?q=http+archive+specification', "OUTPUT: Pingdom's archive first entry request has a url of 'https://duckduckgo.com/?q=http+archive+specification'");
ok($pingdom_ref->{log}->{entries}->[0]->{request}->{httpVersion} eq 'HTTP/1.1', "OUTPUT: Pingdom's archive first entry request has a httpVersion of 'HTTP/1.1'");
ok(scalar @{$pingdom_ref->{log}->{entries}->[0]->{request}->{cookies}} == 0, "OUTPUT: Pingdom's archive first entry request has an empty cookie list");
ok(scalar @{$pingdom_ref->{log}->{entries}->[0]->{request}->{headers}} == 9, "OUTPUT: Pingdom's archive first entry request has 9 headers");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{blocked} == 0, "OUTPUT: Pingdom's archive first entry timings has a blocked value of 0");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{dns} == -1, "OUTPUT: Pingdom's archive first entry timings has a dns value of -1");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{connect} == 125, "OUTPUT: Pingdom's archive first entry timings has a connect value of 125");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{send} == 0, "OUTPUT: Pingdom's archive first entry timings has a send value of 0");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{wait} == 28, "OUTPUT: Pingdom's archive first entry timings has a wait value of 28");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{receive} == 1, "OUTPUT: Pingdom's archive first entry timings has a receive value of 1");
ok($pingdom_ref->{log}->{entries}->[0]->{timings}->{ssl} == 19, "OUTPUT: Pingdom's archive first entry timings has a ssl value of 19");



( run in 2.355 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )