|
@@ -0,0 +1,26 @@
|
|
|
+package url
|
|
|
+
|
|
|
+import "testing"
|
|
|
+
|
|
|
+func TestCreate(t *testing.T) {
|
|
|
+ type args struct {
|
|
|
+ opts []Option
|
|
|
+ }
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ args args
|
|
|
+ want string
|
|
|
+ }{
|
|
|
+ {"1", args{opts: []Option{WithHost("baidu.com")}}, "https://baidu.com"},
|
|
|
+ {"2", args{opts: []Option{WithSchema("http"), WithHost("baidu.com")}}, "http://baidu.com"},
|
|
|
+ {"3", args{opts: []Option{WithSchema("http"), WithHost("baidu.com"), WithPath("/cgi-bin")}}, "http://baidu.com/cgi-bin"},
|
|
|
+ {"4", args{opts: []Option{WithSchema("http"), WithHost("baidu.com"), WithParams(map[string]string{"a": "b"})}}, "http://baidu.com?a=b"},
|
|
|
+ }
|
|
|
+ for _, tt := range tests {
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ if got := Create(tt.args.opts...); got != tt.want {
|
|
|
+ t.Errorf("Create() = %v, want %v", got, tt.want)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|