Browsermob-Proxy
view release on metacpan or search on metacpan
t/CompareParams.t view on Meta::CPAN
name => 'query',
value => 'string'
}, {
name => 'query2',
value => 'string'
}]
}
}, {
request => {
queryString => [{
name => 'query2',
value => 'string2'
}, {
name => 'query3',
value => 'string3'
}]
}
}];
$assert = { query => 'string', query2 => ':query' };
};
it 'should collect query param keys properly' => sub {
my $query_keys = collect_query_param_keys($requests);
cmp_deeply($query_keys, [ 'query', 'query2', 'query3' ]);
};
it 'should pass through a normal assert' => sub {
$assert->{query2} = 'string';
my $mutated = replace_placeholder_values($requests, $assert);
cmp_deeply($mutated, $assert);
};
it 'should mutate an assert with a keyref in it' => sub {
my $mutated = replace_placeholder_values($requests, $assert);
cmp_deeply($mutated, { query => 'string', query2 => 'string' } );
};
it 'should not mutate assert values that are missing a corresponding actual key' => sub {
$assert = { query => ':query_missing' };
my $mutated = replace_placeholder_values($requests, $assert);
cmp_deeply($mutated, $assert);
};
it 'should pass a mutated assert through cmp_request_params' => sub {
my $mutated = replace_placeholder_values($requests, $assert);
ok( cmp_request_params($requests, $mutated) );
};
it 'should fail an assert with a placeholder through cmp_request_params' => sub {
ok( ! cmp_request_params($requests, $assert) );
};
};
SKIP: {
my $server = Browsermob::Server->new;
my $has_connection = IO::Socket::INET->new(
PeerAddr => 'www.perl.org',
PeerPort => 80,
Timeout => 5
);
skip 'No server found for e2e tests', 2
unless $server->_is_listening(5) and $has_connection;
describe 'E2E Comparing params' => sub {
my ($ua, $proxy, $har);
before each => sub {
$ua = LWP::UserAgent->new;
$proxy = $server->create_proxy;
$ua->proxy($proxy->ua_proxy);
$ua->get('http://www.perl.org/?query=string');
$har = $proxy->har;
};
it 'should properly match traffic' => sub {
ok(cmp_request_params($har, { query => 'string' }));
};
it 'should reject non-matching traffic' => sub {
ok( ! cmp_request_params($har, { query2 => 'string2' }));
};
};
}
runtests;
( run in 2.027 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )