(t *testing.T)
| 244 | } |
| 245 | |
| 246 | func TestNewRequest_BaseURL(t *testing.T) { |
| 247 | base, _ := url.Parse("https://example.com/") |
| 248 | |
| 249 | tests := []struct { |
| 250 | path string |
| 251 | want string |
| 252 | }{ |
| 253 | { |
| 254 | path: "/x/path", |
| 255 | want: "https://example.com/path#0x0", |
| 256 | }, |
| 257 | { // Chinese characters 已然 |
| 258 | path: "/x/5bey54S2", |
| 259 | want: "https://example.com/%E5%B7%B2%E7%84%B6#0x0", |
| 260 | }, |
| 261 | } |
| 262 | |
| 263 | for _, tt := range tests { |
| 264 | req, _ := http.NewRequest("GET", tt.path, nil) |
| 265 | r, err := NewRequest(req, base) |
| 266 | if err != nil { |
| 267 | t.Errorf("NewRequest(%v, %v) returned unexpected error: %v", req, base, err) |
| 268 | } |
| 269 | |
| 270 | if got := r.String(); got != tt.want { |
| 271 | t.Errorf("NewRequest(%v, %v) returned %q, want %q", req, base, got, tt.want) |
| 272 | } |
| 273 | } |
| 274 | } |
nothing calls this directly
no test coverage detected