github.com/blend/go-sdk@v1.20220411.3/webutil/mock_request.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  	"net/http"
    12  	"net/url"
    13  )
    14  
    15  // NewMockRequest creates a mock request.
    16  func NewMockRequest(method, path string) *http.Request {
    17  	return &http.Request{
    18  		Method:     method,
    19  		Proto:      "http",
    20  		ProtoMajor: 1,
    21  		ProtoMinor: 1,
    22  		Host:       "localhost:8080",
    23  		RemoteAddr: "127.0.0.1:8080",
    24  		RequestURI: path,
    25  		Header: http.Header{
    26  			HeaderUserAgent: []string{"go-sdk test"},
    27  		},
    28  		URL: &url.URL{
    29  			Scheme:  "http",
    30  			Host:    "localhost",
    31  			Path:    path,
    32  			RawPath: path,
    33  		},
    34  	}
    35  }
    36  
    37  // NewMockRequestWithCookie creates a mock request with a cookie attached to it.
    38  func NewMockRequestWithCookie(method, path, cookieName, cookieValue string) *http.Request {
    39  	req := NewMockRequest(method, path)
    40  	req.AddCookie(&http.Cookie{
    41  		Name:   cookieName,
    42  		Domain: "localhost",
    43  		Path:   "/",
    44  		Value:  cookieValue,
    45  	})
    46  	return req
    47  }