forked from rhnvrm/simples3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers_test.go
More file actions
116 lines (111 loc) · 2.37 KB
/
helpers_test.go
File metadata and controls
116 lines (111 loc) · 2.37 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package simples3
import "testing"
func TestEncodePath(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "empty string",
input: "",
expected: "",
},
{
name: "simple alphanumeric",
input: "abc123",
expected: "abc123",
},
{
name: "unreserved characters",
input: "path-with_special.chars~file/key",
expected: "path-with_special.chars~file/key",
},
{
name: "space character",
input: "hello world",
expected: "hello%20world",
},
{
name: "special characters",
input: "hello!@#$%",
expected: "hello%21%40%23%24%25",
},
{
name: "unicode characters",
input: "文件名",
expected: "%E6%96%87%E4%BB%B6%E5%90%8D",
},
{
name: "mixed content",
input: "folder/文件-2024.txt",
expected: "folder/%E6%96%87%E4%BB%B6-2024.txt",
},
{
name: "comma and parentheses",
input: "file(1),test.txt",
expected: "file%281%29%2Ctest.txt",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := encodePath(tt.input)
if got != tt.expected {
t.Errorf("encodePath() = %v, want %v", got, tt.expected)
}
})
}
}
func TestEncodeTagsHeader(t *testing.T) {
tests := []struct {
name string
tags map[string]string
expected string
}{
{
name: "nil tags",
tags: nil,
expected: "",
},
{
name: "empty tags",
tags: map[string]string{},
expected: "",
},
{
name: "single tag",
tags: map[string]string{"key": "value"},
expected: "key=value",
},
{
name: "multiple tags sorted alphabetically",
tags: map[string]string{
"zebra": "animal",
"apple": "fruit",
"car": "vehicle",
},
expected: "apple=fruit&car=vehicle&zebra=animal",
},
{
name: "tags with special characters",
tags: map[string]string{
"key with space": "value with space",
"key=equals": "value&ersand",
},
expected: "key+with+space=value+with+space&key%3Dequals=value%26ampersand",
},
{
name: "tag with empty value",
tags: map[string]string{"emptyvalue": ""},
expected: "emptyvalue=",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := encodeTagsHeader(tt.tags)
if got != tt.expected {
t.Errorf("encodeTagsHeader() = %v, want %v", got, tt.expected)
}
})
}
}