github.com/blend/go-sdk@v1.20220411.3/webutil/mock_request_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package webutil
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestNewMockRequest(t *testing.T) {
    17  	assert := assert.New(t)
    18  
    19  	req := NewMockRequest("OPTIONS", "/foo")
    20  	assert.Equal("OPTIONS", req.Method)
    21  	assert.Equal("localhost:8080", req.Host)
    22  	assert.Equal("/foo", req.RequestURI)
    23  	assert.NotNil(req.URL)
    24  	assert.Equal("http", req.Proto)
    25  	assert.Equal(1, req.ProtoMajor)
    26  	assert.Equal(1, req.ProtoMinor)
    27  	assert.Equal("http", req.URL.Scheme)
    28  	assert.Equal("/foo", req.URL.Path)
    29  	assert.Equal("127.0.0.1:8080", req.RemoteAddr)
    30  	assert.NotNil(req.Header)
    31  	assert.Equal("go-sdk test", req.Header.Get(HeaderUserAgent))
    32  }
    33  
    34  func TestNewMockRequestWithCookie(t *testing.T) {
    35  	assert := assert.New(t)
    36  	req := NewMockRequestWithCookie("OPTIONS", "/foo", "foo", "bar")
    37  	assert.NotEmpty(req.Cookies())
    38  
    39  	cookie, err := req.Cookie("foo")
    40  	assert.Nil(err)
    41  	assert.Equal("foo", cookie.Name)
    42  	assert.Equal("bar", cookie.Value)
    43  }