MCPcopy Index your code
hub / github.com/containerd/containerd / TestConvert

Function TestConvert

integration/client/convert_test.go:35–85  ·  view source on GitHub ↗

TestConvert creates an image from testImage, with the following conversion: - Media type: Docker -> OCI - Layer type: tar.gz -> tar - Arch: Multi -> Single

(t *testing.T)

Source from the content-addressed store, hash-verified

33// - Layer type: tar.gz -> tar
34// - Arch: Multi -> Single
35func TestConvert(t *testing.T) {
36 if testing.Short() {
37 t.Skip()
38 }
39 ctx, cancel := testContext(t)
40 defer cancel()
41
42 client, err := New(address)
43 if err != nil {
44 t.Fatal(err)
45 }
46 defer client.Close()
47
48 _, err = client.Fetch(ctx, testImage)
49 if err != nil {
50 t.Fatal(err)
51 }
52 dstRef := testImage + "-testconvert"
53 defPlat := platforms.DefaultStrict()
54 opts := []converter.Opt{
55 converter.WithDockerToOCI(true),
56 converter.WithLayerConvertFunc(uncompress.LayerConvertFunc),
57 converter.WithPlatform(defPlat),
58 }
59 dstImg, err := converter.Convert(ctx, client, dstRef, testImage, opts...)
60 if err != nil {
61 t.Fatal(err)
62 }
63 defer func() {
64 if deleteErr := client.ImageService().Delete(ctx, dstRef); deleteErr != nil {
65 t.Fatal(deleteErr)
66 }
67 }()
68 cs := client.ContentStore()
69 plats, err := images.Platforms(ctx, cs, dstImg.Target)
70 if err != nil {
71 t.Fatal(err)
72 }
73 // Assert that the image does not have any extra arch.
74 assert.Equal(t, 1, len(plats))
75 assert.True(t, defPlat.Match(plats[0]))
76
77 // Assert that the media type is converted to OCI and also uncompressed
78 mani, err := images.Manifest(ctx, cs, dstImg.Target, defPlat)
79 if err != nil {
80 t.Fatal(err)
81 }
82 for _, l := range mani.Layers {
83 assert.Equal(t, ocispec.MediaTypeImageLayer, l.MediaType)
84 }
85}

Callers

nothing calls this directly

Calls 15

WithDockerToOCIFunction · 0.92
WithLayerConvertFuncFunction · 0.92
WithPlatformFunction · 0.92
ConvertFunction · 0.92
PlatformsFunction · 0.92
ManifestFunction · 0.92
testContextFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.65
FetchMethod · 0.65
DeleteMethod · 0.65
ImageServiceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…