github.com/aavshr/aws-sdk-go@v1.41.3/private/protocol/rest/build_test.go (about)

     1  package rest
     2  
     3  import (
     4  	"net/http"
     5  	"net/url"
     6  	"testing"
     7  
     8  	"github.com/aavshr/aws-sdk-go/aws"
     9  	"github.com/aavshr/aws-sdk-go/aws/request"
    10  )
    11  
    12  func TestCleanPath(t *testing.T) {
    13  	uri := &url.URL{
    14  		Path:   "//foo//bar",
    15  		Scheme: "https",
    16  		Host:   "host",
    17  	}
    18  	cleanPath(uri)
    19  
    20  	expected := "https://host/foo/bar"
    21  	if a, e := uri.String(), expected; a != e {
    22  		t.Errorf("expect %q URI, got %q", e, a)
    23  	}
    24  }
    25  
    26  func TestMarshalPath(t *testing.T) {
    27  	in := struct {
    28  		Bucket *string `location:"uri" locationName:"bucket"`
    29  		Key    *string `location:"uri" locationName:"key"`
    30  	}{
    31  		Bucket: aws.String("mybucket"),
    32  		Key:    aws.String("my/cool+thing space/object世界"),
    33  	}
    34  
    35  	expectURL := `/mybucket/my/cool+thing space/object世界`
    36  	expectEscapedURL := `/mybucket/my/cool%2Bthing%20space/object%E4%B8%96%E7%95%8C`
    37  
    38  	req := &request.Request{
    39  		HTTPRequest: &http.Request{
    40  			URL: &url.URL{Scheme: "https", Host: "example.com", Path: "/{bucket}/{key+}"},
    41  		},
    42  		Params: &in,
    43  	}
    44  
    45  	Build(req)
    46  
    47  	if req.Error != nil {
    48  		t.Fatalf("unexpected error, %v", req.Error)
    49  	}
    50  
    51  	if a, e := req.HTTPRequest.URL.Path, expectURL; a != e {
    52  		t.Errorf("expect %q URI, got %q", e, a)
    53  	}
    54  
    55  	if a, e := req.HTTPRequest.URL.RawPath, expectEscapedURL; a != e {
    56  		t.Errorf("expect %q escaped URI, got %q", e, a)
    57  	}
    58  
    59  	if a, e := req.HTTPRequest.URL.EscapedPath(), expectEscapedURL; a != e {
    60  		t.Errorf("expect %q escaped URI, got %q", e, a)
    61  	}
    62  
    63  }