MCPcopy Create free account
hub / github.com/containers/image / configForLayers

Function configForLayers

storage/storage_test.go:317–348  ·  view source on GitHub ↗

configForLayers returns a minimally-plausible config for layers

(t *testing.T, layers []testBlob)

Source from the content-addressed store, hash-verified

315
316// configForLayers returns a minimally-plausible config for layers
317func configForLayers(t *testing.T, layers []testBlob) testBlob {
318 rootFS := manifest.Schema2RootFS{
319 Type: "layers",
320 DiffIDs: []digest.Digest{},
321 }
322 for _, l := range layers {
323 rootFS.DiffIDs = append(rootFS.DiffIDs, l.uncompressedDigest)
324 }
325 // Add a unique label so that different calls to configForLayers don’t try to use the same image ID.
326 randomBytes := make([]byte, digest.Canonical.Size())
327 _, err := rand.Read(randomBytes)
328 require.NoError(t, err)
329 config := manifest.Schema2Image{
330 Schema2V1Image: manifest.Schema2V1Image{
331 Config: &manifest.Schema2Config{
332 Labels: map[string]string{"unique": fmt.Sprintf("%x", randomBytes)},
333 },
334 Created: time.Now(),
335 },
336 RootFS: &rootFS,
337 }
338 configBytes, err := json.Marshal(config)
339 require.NoError(t, err)
340 configDigest := digest.Canonical.FromBytes(configBytes)
341 return testBlob{
342 uncompressedDigest: configDigest,
343 compressedDigest: configDigest,
344 uncompressedSize: int64(len(configBytes)),
345 compressedSize: int64(len(configBytes)),
346 data: configBytes,
347 }
348}
349
350func createUncommittedImageDest(t *testing.T, ref types.ImageReference, cache types.BlobInfoCache,
351 layers []testBlob, config *testBlob) (types.ImageDestination, types.UnparsedImage) {

Callers 4

TestWriteReadFunction · 0.85
TestSizeFunction · 0.85
TestDuplicateBlobFunction · 0.85

Calls 2

SizeMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…