github.com/blend/go-sdk@v1.20220411.3/r2/r2test/opt_mock_response_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 r2test
     9  
    10  import (
    11  	"net/http"
    12  	"testing"
    13  
    14  	"github.com/blend/go-sdk/assert"
    15  	"github.com/blend/go-sdk/r2"
    16  )
    17  
    18  func TestOptMockResponseString(t *testing.T) {
    19  	it := assert.New(t)
    20  
    21  	var didCallOriginalCloser bool
    22  	output, meta, err := r2.New(r2.TestURL,
    23  		r2.OptPost(),
    24  		r2.OptCloser(func() error {
    25  			didCallOriginalCloser = true
    26  			return nil
    27  		}),
    28  		OptMockResponseString("this is just a test!"),
    29  	).Bytes()
    30  	it.Nil(err)
    31  	it.Equal(http.StatusOK, meta.StatusCode)
    32  	it.Equal("this is just a test!", string(output))
    33  	it.True(didCallOriginalCloser)
    34  }
    35  
    36  func TestOptMockResponseStringStatus(t *testing.T) {
    37  	it := assert.New(t)
    38  
    39  	var didCallOriginalCloser bool
    40  	output, meta, err := r2.New(r2.TestURL,
    41  		r2.OptPost(),
    42  		r2.OptCloser(func() error {
    43  			didCallOriginalCloser = true
    44  			return nil
    45  		}),
    46  		OptMockResponseStringStatus(http.StatusForbidden, "this is just a test!"),
    47  	).Bytes()
    48  	it.Nil(err)
    49  	it.Equal(http.StatusForbidden, meta.StatusCode)
    50  	it.Equal("this is just a test!", string(output))
    51  	it.True(didCallOriginalCloser)
    52  }