MCPcopy
hub / github.com/minio/minio-go / TestEncodeURL2Path

Function TestEncodeURL2Path

pkg/signer/utils_test.go:28–85  ·  view source on GitHub ↗

Tests url encoding.

(t *testing.T)

Source from the content-addressed store, hash-verified

26
27// Tests url encoding.
28func TestEncodeURL2Path(t *testing.T) {
29 type urlStrings struct {
30 virtualHost bool
31 bucketName string
32 objName string
33 encodedObjName string
34 }
35
36 want := []urlStrings{
37 {
38 virtualHost: true,
39 bucketName: "bucketName",
40 objName: "本語",
41 encodedObjName: "%E6%9C%AC%E8%AA%9E",
42 },
43 {
44 virtualHost: true,
45 bucketName: "bucketName",
46 objName: "本語.1",
47 encodedObjName: "%E6%9C%AC%E8%AA%9E.1",
48 },
49 {
50 virtualHost: true,
51 objName: ">123>3123123",
52 bucketName: "bucketName",
53 encodedObjName: "%3E123%3E3123123",
54 },
55 {
56 virtualHost: true,
57 bucketName: "bucketName",
58 objName: "test 1 2.txt",
59 encodedObjName: "test%201%202.txt",
60 },
61 {
62 virtualHost: false,
63 bucketName: "test.bucketName",
64 objName: "test++ 1.txt",
65 encodedObjName: "test%2B%2B%201.txt",
66 },
67 }
68
69 for i, o := range want {
70 var hostURL string
71 if o.virtualHost {
72 hostURL = fmt.Sprintf("https://%s.s3.amazonaws.com/%s", o.bucketName, o.objName)
73 } else {
74 hostURL = fmt.Sprintf("https://s3.amazonaws.com/%s/%s", o.bucketName, o.objName)
75 }
76 u, err := url.Parse(hostURL)
77 if err != nil {
78 t.Fatalf("Test %d, Error: %v", i+1, err)
79 }
80 expectedPath := "/" + o.bucketName + "/" + o.encodedObjName
81 if foundPath := encodeURL2Path(&http.Request{URL: u}, o.virtualHost); foundPath != expectedPath {
82 t.Fatalf("Test %d, Error: expected = `%v`, found = `%v`", i+1, expectedPath, foundPath)
83 }
84 }
85}

Callers

nothing calls this directly

Calls 1

encodeURL2PathFunction · 0.85

Tested by

no test coverage detected