github.com/prebid/prebid-server/v2@v2.18.0/adapters/response_test.go (about)

     1  package adapters
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prebid/prebid-server/v2/errortypes"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestCheckResponseStatusCodeForErrors(t *testing.T) {
    11  	testCases := []struct {
    12  		name           string
    13  		responseStatus int
    14  		expectedErr    error
    15  	}{
    16  		{
    17  			name:           "bad_input",
    18  			responseStatus: 400,
    19  			expectedErr: &errortypes.BadInput{
    20  				Message: "Unexpected status code: 400. Run with request.debug = 1 for more info",
    21  			},
    22  		},
    23  		{
    24  			name:           "internal_server_error",
    25  			responseStatus: 500,
    26  			expectedErr: &errortypes.BadServerResponse{
    27  				Message: "Unexpected status code: 500. Run with request.debug = 1 for more info",
    28  			},
    29  		},
    30  	}
    31  
    32  	for _, tc := range testCases {
    33  		t.Run(tc.name, func(t *testing.T) {
    34  			err := CheckResponseStatusCodeForErrors(&ResponseData{StatusCode: tc.responseStatus})
    35  			assert.Equal(t, tc.expectedErr, err)
    36  		})
    37  	}
    38  }
    39  
    40  func TestIsResponseStatusCodeNoContent(t *testing.T) {
    41  	assert.True(t, IsResponseStatusCodeNoContent(&ResponseData{StatusCode: 204}))
    42  	assert.False(t, IsResponseStatusCodeNoContent(&ResponseData{StatusCode: 200}))
    43  }