-
Notifications
You must be signed in to change notification settings - Fork 2
/
request_test.go
67 lines (64 loc) · 1.55 KB
/
request_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
package nap
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_buildQueryParamUrl1(t *testing.T) {
type args struct {
fullPath string
queryStruct interface{}
}
tests := []struct {
name string
args args
expected string
wantErr bool
}{
{
name: "Test case 1 - Parse URL with struct request for GET method Successfully",
args: args{
fullPath: "https://github.com/v2/create",
queryStruct: struct {
AppID int32 `url:"app_id"`
AppTransID string `url:"app_trans_id"`
Mac string `url:"mac"`
}{
AppID: 1,
AppTransID: "mmf_transid_210822001",
Mac: "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAPl9eHJltu48w1P",
},
},
expected: "https://github.com/v2/create?app_id=1&app_trans_id=mmf_transid_210822001&mac=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAPl9eHJltu48w1P",
wantErr: false,
},
{
name: "Test case 2 - Request is not a struct, should return error",
args: args{
fullPath: "https://sb-openapi.zalopay.vn/v2/create",
queryStruct: 6,
},
expected: "",
wantErr: true,
},
{
name: "Test case 3 - Full path is invalid, should return error",
args: args{
fullPath: "github.com/%zzzzz",
queryStruct: 6,
},
expected: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
urlStr, err := buildQueryParamUrl(tt.args.fullPath, tt.args.queryStruct)
if tt.wantErr {
assert.Error(t, err)
assert.Empty(t, urlStr)
return
}
assert.Equal(t, tt.expected, urlStr)
})
}
}