url_test.go 791 B

1234567891011121314151617181920212223242526
  1. package url
  2. import "testing"
  3. func TestCreate(t *testing.T) {
  4. type args struct {
  5. opts []Option
  6. }
  7. tests := []struct {
  8. name string
  9. args args
  10. want string
  11. }{
  12. {"1", args{opts: []Option{WithHost("baidu.com")}}, "https://baidu.com"},
  13. {"2", args{opts: []Option{WithSchema("http"), WithHost("baidu.com")}}, "http://baidu.com"},
  14. {"3", args{opts: []Option{WithSchema("http"), WithHost("baidu.com"), WithPath("/cgi-bin")}}, "http://baidu.com/cgi-bin"},
  15. {"4", args{opts: []Option{WithSchema("http"), WithHost("baidu.com"), WithParams(map[string]string{"a": "b"})}}, "http://baidu.com?a=b"},
  16. }
  17. for _, tt := range tests {
  18. t.Run(tt.name, func(t *testing.T) {
  19. if got := Create(tt.args.opts...); got != tt.want {
  20. t.Errorf("Create() = %v, want %v", got, tt.want)
  21. }
  22. })
  23. }
  24. }