...

Source file src/github.com/go-openapi/runtime/client/response_test.go

Documentation: github.com/go-openapi/runtime/client

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package client
    16  
    17  import (
    18  	"bytes"
    19  	"io"
    20  	"net/http"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  
    25  	"github.com/go-openapi/runtime"
    26  )
    27  
    28  func TestResponse(t *testing.T) {
    29  	under := new(http.Response)
    30  	under.Status = "the status message"
    31  	under.StatusCode = 392
    32  	under.Header = make(http.Header)
    33  	under.Header.Set("Blah", "blahblah")
    34  	under.Body = io.NopCloser(bytes.NewBufferString("some content"))
    35  
    36  	var resp runtime.ClientResponse = response{under}
    37  	assert.EqualValues(t, under.StatusCode, resp.Code())
    38  	assert.Equal(t, under.Status, resp.Message())
    39  	assert.Equal(t, "blahblah", resp.GetHeader("blah"))
    40  	assert.Equal(t, []string{"blahblah"}, resp.GetHeaders("blah"))
    41  	assert.Equal(t, under.Body, resp.Body())
    42  }
    43  

View as plain text