github.com/blend/go-sdk@v1.20220411.3/r2/opt_path_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 r2
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestOptPath(t *testing.T) {
    17  	its := assert.New(t)
    18  
    19  	r := New(TestURL, OptPath("/not-foo"))
    20  	its.Nil(r.Err)
    21  	its.Equal("/not-foo", r.Request.URL.Path)
    22  
    23  	var unset Request
    24  	its.NotNil(OptPath("/not-foo")(&unset))
    25  }
    26  
    27  func TestOptPathf(t *testing.T) {
    28  	its := assert.New(t)
    29  
    30  	r := New(TestURL, OptPathf("/not-foo/%s", "bar"))
    31  	its.Nil(r.Err)
    32  	its.Equal("/not-foo/bar", r.Request.URL.Path)
    33  
    34  	var unset Request
    35  	its.NotNil(OptPathf("/not-foo/%s", "bar")(&unset))
    36  }
    37  
    38  func TestOptPathParameterized(t *testing.T) {
    39  	its := assert.New(t)
    40  
    41  	r := New(TestURL, OptPathParameterized("resource/:resource_id", map[string]string{"resource_id": "1234"}))
    42  	its.Nil(r.Err)
    43  	its.Equal("/resource/1234", r.Request.URL.Path)
    44  	its.Equal("/resource/:resource_id", GetParameterizedPath(r.Request.Context()))
    45  
    46  	var unset Request
    47  	its.NotNil(OptPathParameterized("resource/:resource_id", map[string]string{"resource_id": "1234"})(&unset))
    48  
    49  	its.NotNil(OptPathParameterized("resource/:resource_id", map[string]string{})(r))
    50  	its.Nil(OptPathParameterized("resource/:resource_id", map[string]string{"resource_id": "1234", "other_id": "5678"})(r))
    51  }