Infrastructure/HTTP.pm

filter: Statementstmt 51.8% 42 / 81 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 32.0% 8 / 25 Podpod 0.0% 0 / 1 totaltotal 42.7% 50 / 117 CC 6 SCAR 19.0
CC
6
Cov
46%
__ANON__
30.0
__ANON__
6.0
S
2.0
CRAP 6.7
« Infrastructure/Logfile.pm ↑ Summary Infrastructure/Process.pm »
1 package Test::BDD::Infrastructure::HTTP;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.005'; # VERSION
7 # ABSTRACT: cucumber step definitions for http based checks
8
9 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Test::BDD::Cucumber::StepFile qw( Given When Then );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub S { Test::BDD::Cucumber::StepFile::S }
Subroutine S: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 1 ▶use Test::BDD::Infrastructure::Utils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 convert_unit convert_cmp_operator $CMP_OPERATOR_RE convert_interval
16 1 lookup_config );
17  
18 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 0 ▶Given qr/the http URL (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 S->{'uri'} = URI->new( lookup_config($1) );
25 0 S->{'request'} = HTTP::Request->new(
26 method => 'GET',
27 );
28 0 S->{'agent'} = LWP::UserAgent->new;
29 1 };
30  
31 0 ▶Given qr/the http URL path is (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 S->{'uri'}->path( lookup_config($1) );
33 1 };
34  
35 0 ▶Given qr/the http user agent is (\S+)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 S->{'agent'}->agent( $1 );
37 1 };
38 0 ▶Given qr/the http proxy for (\S+) is (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 S->{'agent'}->proxy( $1 => $2 );
40 1 };
41 0 ▶Given qr/the http ssl option (\S+) is (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 S->{'agent'}->ssl_opts( $1 => $2 );
43 1 };
44 0 ▶Given qr/the http request method is (\S+)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 S->{'request'}->method( $1 );
46 1 };
47  
48 0 ▶Given qr/the http request header (\S+) is set to (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 S->{'request'}->header( $1 => $2 );
50 1 };
51  
52 0 ▶Given qr/the http timeout is set to (\d+) seconds/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 S->{'agent'}->timeout( $1 );
54 1 };
55  
56 0 ▶When qr/the http request is (?:sent|executed)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 S->{'request'}->uri( S->{'uri'}->as_string );
58 0 my $response = S->{'agent'}->request( S->{'request'} );
59 0 S->{'response'} = $response;
60 1 };
61  
62  
63 0 ▶Then qr/the http response must be (?:a )?(successfull|error|failure|redirect|info(?:rmational)?)/, sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
64 0 my $check = $1;
65 0 diag('response code is '.S->{'response'}->status_line );
66 0 ▶ if( $check eq 'successfull' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($check eq 'successfull') { } 0 0 0
elsif ($check =~ /(error|failure)/) { } 0 0 0
elsif ($check eq 'redirect') { } 0 0 0
elsif ($check =~ /^info/) { } 0 0 0
67 0 ok( S->{'response'}->is_success , 'successfull http response');
68 } elsif( $check =~ /(error|failure)/ ) {
69 0 ok( S->{'response'}->is_error , 'error http response');
70 } elsif( $check eq 'redirect' ) {
71 0 ok( S->{'response'}->is_redirect , 'redirect http response');
72 } elsif( $check =~ /^info/ ) {
73 0 ok( S->{'response'}->is_info , 'info http response');
74 }
75 1 };
76  
77 0 ▶Then qr/the http response status code must be (\d+)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 my $code = $1;
79 0 cmp_ok( S->{'response'}->code, '==', $code, "the status code must be $code");
80 1 };
81 0 ▶Then qr/the http response status message must be like (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 my $regex = $1;
83 0 like( S->{'response'}->message, qr/$regex/, "the status message must be like $regex");
84 1 };
85 0 ▶Then qr/the http response header (\S+) must be like (.*)/, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
86 0 my $header = $1;
87 0 my $regex = $2;
88 0 my $value = S->{'response'}->header($header);
89 0 ▶ if( ! defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
90 0 fail("header $header is not set in response");
91 0 return;
92 }
93 0 like( $value, qr/$regex/, "the header $header must be like $regex");
94 1 };
95  
96 0 ▶Then qr/the http response content must be unlike (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 my $regex = $1;
98 0 unlike( S->{'response'}->content, qr/$regex/, "the content must be unlike $regex");
99 1 };
100 0 ▶Then qr/the http response content must be like (.*)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 my $regex = $1;
102 0 like( S->{'response'}->content, qr/$regex/, "the content must be like $regex");
103 1 };
104  
105 0 ▶Then qr/the http response content size must be $CMP_OPERATOR_RE (\d+) (\S+)/, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 my $op = convert_cmp_operator( $1 );
107 0 my $size = convert_unit( $2, $3 );
108 0 cmp_ok( length S->{'response'}->content, $op, $size, "content must be $op $size" );
109 1 };
110  
111 1 1;
112  
113 __END__
« Infrastructure/Logfile.pm ↑ Summary Infrastructure/Process.pm »