(t *testing.T)
| 1410 | } |
| 1411 | |
| 1412 | func TestWriteForeignLayerIfOptionSet(t *testing.T) { |
| 1413 | // Set up an image with a foreign layer. |
| 1414 | base := setupImage(t) |
| 1415 | foreignLayer, err := random.Layer(1024, types.DockerForeignLayer) |
| 1416 | if err != nil { |
| 1417 | t.Fatal("random.Layer:", err) |
| 1418 | } |
| 1419 | img, err := mutate.AppendLayers(base, foreignLayer) |
| 1420 | if err != nil { |
| 1421 | t.Fatal(err) |
| 1422 | } |
| 1423 | |
| 1424 | expectedRepo := "write/time" |
| 1425 | headPathPrefix := fmt.Sprintf("/v2/%s/blobs/", expectedRepo) |
| 1426 | initiatePath := fmt.Sprintf("/v2/%s/blobs/uploads/", expectedRepo) |
| 1427 | manifestPath := fmt.Sprintf("/v2/%s/manifests/latest", expectedRepo) |
| 1428 | uploadPath := "/upload" |
| 1429 | commitPath := "/commit" |
| 1430 | var numUploads int32 |
| 1431 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1432 | if r.Method == http.MethodHead && strings.HasPrefix(r.URL.Path, headPathPrefix) && r.URL.Path != initiatePath { |
| 1433 | http.Error(w, "NotFound", http.StatusNotFound) |
| 1434 | return |
| 1435 | } |
| 1436 | switch r.URL.Path { |
| 1437 | case "/v2/": |
| 1438 | w.WriteHeader(http.StatusOK) |
| 1439 | case initiatePath: |
| 1440 | if r.Method != http.MethodPost { |
| 1441 | t.Errorf("Method; got %v, want %v", r.Method, http.MethodPost) |
| 1442 | } |
| 1443 | w.Header().Set("Location", uploadPath) |
| 1444 | http.Error(w, "Accepted", http.StatusAccepted) |
| 1445 | case uploadPath: |
| 1446 | if r.Method != http.MethodPatch { |
| 1447 | t.Errorf("Method; got %v, want %v", r.Method, http.MethodPatch) |
| 1448 | } |
| 1449 | atomic.AddInt32(&numUploads, 1) |
| 1450 | w.Header().Set("Location", commitPath) |
| 1451 | http.Error(w, "Created", http.StatusCreated) |
| 1452 | case commitPath: |
| 1453 | http.Error(w, "Created", http.StatusCreated) |
| 1454 | case manifestPath: |
| 1455 | if r.Method == http.MethodHead { |
| 1456 | w.Header().Set("Content-Type", string(types.DockerManifestSchema1Signed)) |
| 1457 | w.Header().Set("Docker-Content-Digest", fakeDigest) |
| 1458 | w.Header().Set("Content-Length", "123") |
| 1459 | return |
| 1460 | } |
| 1461 | if r.Method != http.MethodPut && r.Method != http.MethodHead { |
| 1462 | t.Errorf("Method; got %v, want %v", r.Method, http.MethodPut) |
| 1463 | } |
| 1464 | http.Error(w, "Created", http.StatusCreated) |
| 1465 | default: |
| 1466 | t.Fatalf("Unexpected path: %v", r.URL.Path) |
| 1467 | } |
| 1468 | })) |
| 1469 | defer server.Close() |
nothing calls this directly
no test coverage detected
searching dependent graphs…