| 313 | } |
| 314 | |
| 315 | func TestObjectWithPrefix(t *testing.T) { |
| 316 | tests := []struct { |
| 317 | name string |
| 318 | prefix string |
| 319 | objectName string |
| 320 | keyPath backend.KeyPath |
| 321 | httpHandler func(t *testing.T) http.HandlerFunc |
| 322 | }{ |
| 323 | { |
| 324 | name: "with prefix", |
| 325 | prefix: "test_storage", |
| 326 | objectName: "object", |
| 327 | keyPath: backend.KeyPath{"test_path"}, |
| 328 | httpHandler: func(t *testing.T) http.HandlerFunc { |
| 329 | return func(w http.ResponseWriter, r *http.Request) { |
| 330 | if r.Method == "GET" { |
| 331 | _, _ = w.Write([]byte(` |
| 332 | { |
| 333 | "location": "US", |
| 334 | "storageClass": "STANDARD" |
| 335 | } |
| 336 | `)) |
| 337 | return |
| 338 | } |
| 339 | |
| 340 | assert.Equal(t, "/upload/storage/v1/b/blerg/o", r.URL.Path) |
| 341 | assert.True(t, r.URL.Query().Get("name") == "test_storage/test_path/object") |
| 342 | _, _ = w.Write([]byte(`{}`)) |
| 343 | } |
| 344 | }, |
| 345 | }, |
| 346 | { |
| 347 | name: "without prefix", |
| 348 | objectName: "object", |
| 349 | keyPath: backend.KeyPath{"test_path"}, |
| 350 | httpHandler: func(t *testing.T) http.HandlerFunc { |
| 351 | return func(w http.ResponseWriter, r *http.Request) { |
| 352 | if r.Method == "GET" { |
| 353 | _, _ = w.Write([]byte(` |
| 354 | { |
| 355 | "location": "US", |
| 356 | "storageClass": "STANDARD" |
| 357 | } |
| 358 | `)) |
| 359 | return |
| 360 | } |
| 361 | |
| 362 | assert.Equal(t, "/upload/storage/v1/b/blerg/o", r.URL.Path) |
| 363 | assert.True(t, r.URL.Query().Get("name") == "test_path/object") |
| 364 | _, _ = w.Write([]byte(`{}`)) |
| 365 | } |
| 366 | }, |
| 367 | }, |
| 368 | } |
| 369 | |
| 370 | for _, tc := range tests { |
| 371 | t.Run(tc.name, func(t *testing.T) { |
| 372 | server := testServer(t, tc.httpHandler(t)) |