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