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

Function TestSourcePrepareLayerData

docker/internal/tarfile/src_test.go:17–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestSourcePrepareLayerData(t *testing.T) {
18 // Just a smoke test to verify prepareLayerData does not crash on missing data
19 for _, c := range []struct {
20 config string
21 shouldFail bool
22 }{
23 {`{}`, true}, // No RootFS entry: can fail, shouldn’t crash
24 {`{"rootfs":{}}`, false}, // Useless no-layer configuration
25 } {
26 cache := memory.New()
27 var tarfileBuffer bytes.Buffer
28 ctx := context.Background()
29
30 writer := NewWriter(&tarfileBuffer)
31 dest := NewDestination(nil, writer, "transport name", nil, nil)
32 // No layers
33 configInfo, err := dest.PutBlob(ctx, strings.NewReader(c.config),
34 types.BlobInfo{Size: -1}, cache, true)
35 require.NoError(t, err, c.config)
36 manifest, err := manifest.Schema2FromComponents(
37 manifest.Schema2Descriptor{
38 MediaType: manifest.DockerV2Schema2ConfigMediaType,
39 Size: configInfo.Size,
40 Digest: configInfo.Digest,
41 }, []manifest.Schema2Descriptor{}).Serialize()
42 require.NoError(t, err, c.config)
43 err = dest.PutManifest(ctx, manifest, nil)
44 require.NoError(t, err, c.config)
45 err = writer.Close()
46 require.NoError(t, err, c.config)
47
48 reader, err := NewReaderFromStream(nil, &tarfileBuffer)
49 require.NoError(t, err, c.config)
50 src := NewSource(reader, true, "transport name", nil, -1)
51 require.NoError(t, err, c.config)
52 defer src.Close()
53 configStream, _, err := src.GetBlob(ctx, types.BlobInfo{
54 Digest: configInfo.Digest,
55 Size: -1,
56 }, cache)
57 if !c.shouldFail {
58 require.NoError(t, err, c.config)
59 config2, err := io.ReadAll(configStream)
60 require.NoError(t, err, c.config)
61 assert.Equal(t, []byte(c.config), config2, c.config)
62 } else {
63 assert.Error(t, err, c.config)
64 }
65 }
66}

Callers

nothing calls this directly

Calls 13

PutBlobMethod · 0.95
PutManifestMethod · 0.95
CloseMethod · 0.95
CloseMethod · 0.95
GetBlobMethod · 0.95
NewFunction · 0.92
Schema2FromComponentsFunction · 0.92
NewReaderFromStreamFunction · 0.85
NewSourceFunction · 0.85
NewWriterFunction · 0.70
NewDestinationFunction · 0.70
SerializeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…