-
Notifications
You must be signed in to change notification settings - Fork 905
/
sign_util_test.go
84 lines (76 loc) · 1.8 KB
/
sign_util_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package auth
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
func TestIsEmpty(t *testing.T) {
type args struct {
s string
allowSpace bool
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
{"test1", args{s: " ", allowSpace: false}, true},
{"test2", args{s: " ", allowSpace: true}, false},
{"test3", args{s: "hello,dubbo", allowSpace: false}, false},
{"test4", args{s: "hello,dubbo", allowSpace: true}, false},
{"test5", args{s: "", allowSpace: true}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsEmpty(tt.args.s, tt.args.allowSpace); got != tt.want {
t.Errorf("IsEmpty() = %v, want %v", got, tt.want)
}
})
}
}
func TestSign(t *testing.T) {
metadata := "com.ikurento.user.UserProvider::sayHi"
key := "key"
signature := Sign(metadata, key)
assert.NotNil(t, signature)
}
func TestSignWithParams(t *testing.T) {
metadata := "com.ikurento.user.UserProvider::sayHi"
key := "key"
params := []interface{}{
"a", 1, struct {
Name string
Id int64
}{"YuYu", 1},
}
signature, _ := SignWithParams(params, metadata, key)
assert.False(t, IsEmpty(signature, false))
}
func Test_doSign(t *testing.T) {
sign := doSign([]byte("DubboGo"), "key")
sign1 := doSign([]byte("DubboGo"), "key")
sign2 := doSign([]byte("DubboGo"), "key2")
assert.NotNil(t, sign)
assert.Equal(t, sign1, sign)
assert.NotEqual(t, sign1, sign2)
}
func Test_toBytes(t *testing.T) {
params := []interface{}{
"a", 1, struct {
Name string
Id int64
}{"YuYu", 1},
}
params2 := []interface{}{
"a", 1, struct {
Name string
Id int64
}{"YuYu", 1},
}
jsonBytes, _ := toBytes(params)
jsonBytes2, _ := toBytes(params2)
assert.NotNil(t, jsonBytes)
assert.Equal(t, jsonBytes, jsonBytes2)
}