Skip to content

Commit c077725

Browse files
committed
Fixed unit tests with product check
1 parent 5a15755 commit c077725

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

lib/Search/Elasticsearch/Role/Cxn.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ sub _decompress_body {
340340
sub process_response {
341341
#===================================
342342
my ( $self, $params, $code, $msg, $body, $headers ) = @_;
343-
343+
344344
# Product check
345345
if ( $code >= 200 and $code < 300 ) {
346-
if (!defined $headers->{'X-Elastic-Product'} || $headers->{'X-Elastic-Product'} eq 'Elasticsearch') {
346+
if (!defined $headers->{'X-Elastic-Product'} || $headers->{'X-Elastic-Product'} ne 'Elasticsearch') {
347347
throw( "ProductCheck", "The client noticed that the server is not Elasticsearch and we do not support this unknown product" );
348348
}
349349
}

t/60_Cxn/20_process_response.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ my ( $code, $response );
2929
### OK GET
3030
( $code, $response )
3131
= $c->process_response( { method => 'GET', ignore => [] },
32-
200, "OK", '{"ok":1}', { 'content-type' => 'application/json' } );
32+
200, "OK", '{"ok":1}', { 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' } );
3333

3434
is $code, 200, "OK GET - code";
3535
cmp_deeply $response, { ok => 1 }, "OK GET - body";
3636

3737
### OK GET - Text body
3838
( $code, $response )
3939
= $c->process_response( { method => 'GET', ignore => [] },
40-
200, "OK", 'Foo', { 'content-type' => 'text/plain' } );
40+
200, "OK", 'Foo', { 'content-type' => 'text/plain', 'X-Elastic-Product' => 'Elasticsearch' } );
4141

4242
is $code, 200, "OK GET Text body - code";
4343
cmp_deeply $response, 'Foo', "OK GET Text body - body";
4444

4545
### OK GET - Empty body
4646
( $code, $response )
4747
= $c->process_response( { method => 'GET', ignore => [] },
48-
200, "OK", '' );
48+
200, "OK", '', { 'X-Elastic-Product' => 'Elasticsearch' } );
4949

5050
is $code, 200, "OK GET Empty body - code";
5151
cmp_deeply $response, '', "OK GET Empty body - body";
5252

5353
### OK HEAD
5454
( $code, $response )
55-
= $c->process_response( { method => 'HEAD', ignore => [] }, 200, "OK" );
55+
= $c->process_response( { method => 'HEAD', ignore => [] }, 200, "OK", '', { 'X-Elastic-Product' => 'Elasticsearch' } );
5656

5757
is $code, 200, "OK HEAD - code";
5858
is $response, 1, "OK HEAD - body";
@@ -82,7 +82,7 @@ is $response, undef, "Missing GET - body";
8282
### Missing HEAD
8383
( $code, $response )
8484
= $c->process_response( { method => 'HEAD', ignore => [] },
85-
404, "Missing" );
85+
404, "Missing", '', { 'X-Elastic-Product' => 'Elasticsearch' });
8686
is $code, 404, "Missing HEAD - code";
8787
is $response, undef, "Missing HEAD - body";
8888

@@ -92,7 +92,7 @@ throws_ok {
9292
{ method => 'GET', ignore => [] },
9393
400, "Request",
9494
'{"error":"error in body"}',
95-
{ 'content-type' => 'application/json' }
95+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
9696
);
9797
}
9898
qr/\[400\] error in body/, "Request error";

t/60_Cxn_Async/20_process_response.t

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ my ( $code, $response );
2929
### OK GET
3030
( $code, $response )
3131
= $c->process_response( { method => 'GET', ignore => [] },
32-
200, "OK", '{"ok":1}', { 'content-type' => 'application/json' } );
32+
200, "OK", '{"ok":1}', { 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' } );
3333

3434
is $code, 200, "OK GET - code";
3535
cmp_deeply $response, { ok => 1 }, "OK GET - body";
3636

3737
### OK GET - Text body
3838
( $code, $response )
3939
= $c->process_response( { method => 'GET', ignore => [] },
40-
200, "OK", 'Foo', { 'content-type' => 'text/plain' } );
40+
200, "OK", 'Foo', { 'content-type' => 'text/plain', 'X-Elastic-Product' => 'Elasticsearch' } );
4141

4242
is $code, 200, "OK GET Text body - code";
4343
cmp_deeply $response, 'Foo', "OK GET Text body - body";
4444

4545
### OK GET - Empty body
4646
( $code, $response )
4747
= $c->process_response( { method => 'GET', ignore => [] }, 200, "OK",
48-
'' );
48+
'', { 'X-Elastic-Product' => 'Elasticsearch' } );
4949

5050
is $code, 200, "OK GET Empty body - code";
5151
cmp_deeply $response, '', "OK GET Empty body - body";
5252

5353
### OK HEAD
5454
( $code, $response )
55-
= $c->process_response( { method => 'HEAD', ignore => [] }, 200, "OK" );
55+
= $c->process_response( { method => 'HEAD', ignore => [] }, 200, "OK", '', { 'X-Elastic-Product' => 'Elasticsearch' });
5656

5757
is $code, 200, "OK HEAD - code";
5858
is $response, 1, "OK HEAD - body";
@@ -63,7 +63,7 @@ throws_ok {
6363
{ method => 'GET', ignore => [] },
6464
404, "Missing",
6565
'{"error": "Something is missing"}',
66-
{ 'content-type' => 'application/json' }
66+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
6767
);
6868
}
6969
qr/Missing/, "Missing GET";
@@ -73,7 +73,7 @@ qr/Missing/, "Missing GET";
7373
{ method => 'GET', ignore => [404] },
7474
404, "Missing",
7575
'{"error": "Something is missing"}',
76-
{ 'content-type' => 'application/json' }
76+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
7777
);
7878

7979
is $code, 404, "Missing GET - code";
@@ -92,7 +92,7 @@ throws_ok {
9292
{ method => 'GET', ignore => [] },
9393
400, "Request",
9494
'{"error":"error in body"}',
95-
{ 'content-type' => 'application/json' }
95+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
9696
);
9797
}
9898
qr/\[400\] error in body/, "Request error";

t/lib/MockAsyncCxn.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ sub perform_request {
118118
$response->{code}, # code
119119
$response->{error}, # msg
120120
$response->{content}, # body
121-
{ 'content-type' => 'application/json' }
121+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
122122
)
123123
);
124124
1;

t/lib/MockCxn.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sub perform_request {
110110
$response->{code}, # code
111111
$response->{error}, # msg
112112
$response->{content}, # body
113-
{ 'content-type' => 'application/json' }
113+
{ 'content-type' => 'application/json', 'X-Elastic-Product' => 'Elasticsearch' }
114114
);
115115
}
116116

0 commit comments

Comments
 (0)