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

Function testExportImport

integration/client/import_test.go:75–149  ·  view source on GitHub ↗
(t *testing.T, imageName string)

Source from the content-addressed store, hash-verified

73}
74
75func testExportImport(t *testing.T, imageName string) {
76 if testing.Short() {
77 t.Skip()
78 }
79 ctx, cancel := testContext(t)
80 defer cancel()
81
82 client, err := New(address)
83 if err != nil {
84 t.Fatal(err)
85 }
86 defer client.Close()
87
88 _, err = client.Fetch(ctx, imageName, WithPlatformMatcher(platforms.Default()))
89 if err != nil {
90 t.Fatal(err)
91 }
92
93 dstFile, err := os.Create(filepath.Join(t.TempDir(), "export-import-test"))
94 require.NoError(t, err)
95 t.Cleanup(func() {
96 dstFile.Close()
97 })
98
99 err = client.Export(ctx, dstFile, archive.WithPlatform(platforms.Default()), archive.WithImage(client.ImageService(), imageName))
100 require.NoError(t, err)
101
102 client.ImageService().Delete(ctx, imageName)
103
104 // Seek to beginning of file in preparation for Import()
105 dstFile.Seek(0, 0)
106
107 opts := []ImportOpt{
108 WithImageRefTranslator(archive.AddRefPrefix("foo/bar")),
109 }
110
111 imgrecs, err := client.Import(ctx, dstFile, opts...)
112 require.NoError(t, err, "Import failed: %+v", err)
113
114 // We need to unpack the image, especially if it's multilayered.
115 for _, img := range imgrecs {
116 image := NewImage(client, img)
117
118 // TODO: Show unpack status
119 t.Logf("unpacking %s (%s)...", img.Name, img.Target.Digest)
120 err = image.Unpack(ctx, "")
121 require.NoError(t, err, "Error while unpacking image: %+v", err)
122 t.Log("done")
123 }
124
125 // we're triggering the Garbage Collector to do its job.
126 ls := client.LeasesService()
127 l, err := ls.Create(ctx, leases.WithRandomID(), leases.WithExpiration(time.Hour))
128 require.NoError(t, err, "Error while creating lease: %+v", err)
129
130 if err := ls.Delete(ctx, l, leases.SynchronousDelete); err != nil {
131 t.Fatalf("Error while deleting lease: %+v", err)
132 }

Callers 2

TestExportAndImportFunction · 0.85

Calls 15

UnpackMethod · 0.95
DeleteMethod · 0.95
WithPlatformFunction · 0.92
WithRandomIDFunction · 0.92
WithExpirationFunction · 0.92
WithImageConfigFunction · 0.92
testContextFunction · 0.85
WithPlatformMatcherFunction · 0.85
WithImageRefTranslatorFunction · 0.85
NewImageFunction · 0.85
WithNewSpecFunction · 0.85
FatalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…