1515// specific language governing permissions and limitations
1616// under the License.
1717
18+ //go:build !integration
1819// +build !integration
1920
2021package elasticsearch
@@ -389,10 +390,10 @@ func TestClientMetrics(t *testing.T) {
389390
390391func TestResponseCheckOnly (t * testing.T ) {
391392 tests := []struct {
392- name string
393- response * http.Response
394- requestErr error
395- wantErr bool
393+ name string
394+ response * http.Response
395+ requestErr error
396+ wantErr bool
396397 }{
397398 {
398399 name : "Valid answer with header" ,
@@ -410,14 +411,62 @@ func TestResponseCheckOnly(t *testing.T) {
410411 wantErr : true ,
411412 },
412413 {
413- name : "Valid answer with http error code " ,
414+ name : "Valid answer with header and response check " ,
414415 response : & http.Response {
415- StatusCode : http .StatusUnauthorized ,
416416 Header : http.Header {"X-Elastic-Product" : []string {"Elasticsearch" }},
417- Body : ioutil .NopCloser (strings .NewReader ("{}" )),
417+ Body : ioutil .NopCloser (strings .NewReader ("{}" )),
418418 },
419419 wantErr : false ,
420420 },
421+ {
422+ name : "Valid answer without header and response check" ,
423+ response : & http.Response {
424+ Body : ioutil .NopCloser (strings .NewReader ("{}" )),
425+ },
426+ wantErr : true ,
427+ },
428+ {
429+ name : "Request failed" ,
430+ response : nil ,
431+ requestErr : errors .New ("request failed" ),
432+ wantErr : true ,
433+ },
434+ {
435+ name : "Valid request, 500 response" ,
436+ response : & http.Response {
437+ StatusCode : http .StatusInternalServerError ,
438+ Body : ioutil .NopCloser (strings .NewReader ("" )),
439+ },
440+ requestErr : nil ,
441+ wantErr : true ,
442+ },
443+ {
444+ name : "Valid request, 404 response" ,
445+ response : & http.Response {
446+ StatusCode : http .StatusNotFound ,
447+ Body : ioutil .NopCloser (strings .NewReader ("" )),
448+ },
449+ requestErr : nil ,
450+ wantErr : true ,
451+ },
452+ {
453+ name : "Valid request, 403 response" ,
454+ response : & http.Response {
455+ StatusCode : http .StatusForbidden ,
456+ Body : ioutil .NopCloser (strings .NewReader ("" )),
457+ },
458+ requestErr : nil ,
459+ wantErr : false ,
460+ },
461+ {
462+ name : "Valid request, 401 response" ,
463+ response : & http.Response {
464+ StatusCode : http .StatusUnauthorized ,
465+ Body : ioutil .NopCloser (strings .NewReader ("" )),
466+ },
467+ requestErr : nil ,
468+ wantErr : false ,
469+ },
421470 }
422471
423472 for _ , tt := range tests {
@@ -435,7 +484,6 @@ func TestResponseCheckOnly(t *testing.T) {
435484 }
436485}
437486
438-
439487func TestProductCheckError (t * testing.T ) {
440488 var requestPaths []string
441489 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -472,7 +520,6 @@ func TestProductCheckError(t *testing.T) {
472520 }
473521}
474522
475-
476523func TestFingerprint (t * testing.T ) {
477524 body := []byte (`{"body": true"}"` )
478525 server := httptest .NewTLSServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -482,7 +529,7 @@ func TestFingerprint(t *testing.T) {
482529 defer server .Close ()
483530
484531 config := Config {
485- Addresses : []string {server .URL },
532+ Addresses : []string {server .URL },
486533 DisableRetry : true ,
487534 }
488535
@@ -507,4 +554,4 @@ func TestFingerprint(t *testing.T) {
507554 if bytes .Compare (data , body ) != 0 {
508555 t .Fatalf ("unexpected payload returned: expected: %s, got: %s" , body , data )
509556 }
510- }
557+ }
0 commit comments