MCPcopy
hub / github.com/google/go-containerregistry / TestWriteForeignLayerIfOptionSet

Function TestWriteForeignLayerIfOptionSet

pkg/v1/remote/write_test.go:1412–1488  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1410}
1411
1412func 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()

Callers

nothing calls this directly

Calls 8

LayerFunction · 0.92
AppendLayersFunction · 0.92
NewTagFunction · 0.92
setupImageFunction · 0.85
WriteFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…