gopkg/gin/request/util_test.go
2021-07-25 19:05:59 +08:00

44 lines
1.4 KiB
Go

// Package request...
//
// Description : request...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021-07-24 9:21 下午
package request
import (
"net/url"
"reflect"
"testing"
)
// TestParseGetRequestURI 测试解析请求uri
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 9:28 下午 2021/7/24
func TestParseGetRequestURI(t *testing.T) {
type args struct {
url *url.URL
}
tests := []struct {
name string
args args
want map[string][]string
}{
{"不存在任何参数", args{url: &url.URL{RawQuery: ""}}, make(map[string][]string)},
{"正常参数", args{url: &url.URL{RawQuery: "name=zhang&age=10"}}, map[string][]string{"name": {"zhang"}, "age": {"10"}}},
{"多个相同参数", args{url: &url.URL{RawQuery: "name=zhang&age=10&name=wang"}}, map[string][]string{"name": {"zhang", "wang"}, "age": {"10"}}},
{"末尾存在&符", args{url: &url.URL{RawQuery: "name=zhang&age=10&name=wang&"}}, map[string][]string{"name": {"zhang", "wang"}, "age": {"10"}}},
{"缺失=号", args{url: &url.URL{RawQuery: "name=zhang&age=10&name=wang&test"}}, map[string][]string{"name": {"zhang", "wang"}, "age": {"10"}, "test": {""}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseGetRequestURI(tt.args.url); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseGetRequestURI() = %v, want %v", got, tt.want)
}
})
}
}