-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
helper_test.go
63 lines (57 loc) · 1.29 KB
/
helper_test.go
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 cos
import (
"fmt"
"testing"
)
func Test_calSHA1Digest(t *testing.T) {
want := "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
got := fmt.Sprintf("%x", calSHA1Digest([]byte("test")))
if got != want {
t.Errorf("calSHA1Digest request sha1: %+v, want %+v", got, want)
}
}
func Test_calMD5Digest(t *testing.T) {
want := "098f6bcd4621d373cade4e832627b4f6"
got := fmt.Sprintf("%x", calMD5Digest([]byte("test")))
if got != want {
t.Errorf("calMD5Digest request md5: %+v, want %+v", got, want)
}
}
func Test_encodeURIComponent(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{
name: "empty",
args: args{""},
want: "",
},
{
name: "no escape",
args: args{"0123456789abcdefghijkhlmnopqrstuvwxyzABCDEFGHIJKHLMNOPQRSTUVWXYZ-_.!~*'()"},
want: "0123456789abcdefghijkhlmnopqrstuvwxyzABCDEFGHIJKHLMNOPQRSTUVWXYZ-_.!~*'()",
},
{
name: "escape",
args: args{"+ $@#/"},
want: "%2B%20%24%40%23%2F",
},
{
name: "escape+no",
args: args{"+ $abc@#13/0"},
want: "%2B%20%24abc%40%2313%2F0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := encodeURIComponent(tt.args.s); got != tt.want {
t.Errorf("encodeURIComponent() = %v, want %v", got, tt.want)
}
})
}
}