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

Function TestMultiWriteDifferentImages

pkg/v1/tarball/write_test.go:147–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestMultiWriteDifferentImages(t *testing.T) {
148 // Make a tempfile for tarball writes.
149 fp, err := os.CreateTemp("", "")
150 if err != nil {
151 t.Fatalf("Error creating temp file.")
152 }
153 t.Log(fp.Name())
154 defer fp.Close()
155 defer os.Remove(fp.Name())
156
157 // Make a random image
158 randImage1, err := random.Image(256, 8)
159 if err != nil {
160 t.Fatalf("Error creating random image 1.")
161 }
162
163 // Make another random image
164 randImage2, err := random.Image(256, 8)
165 if err != nil {
166 t.Fatalf("Error creating random image 2.")
167 }
168
169 // Make another random image
170 randImage3, err := random.Image(256, 8)
171 if err != nil {
172 t.Fatalf("Error creating random image 3.")
173 }
174
175 // Create two tags, one pointing to each image created.
176 tag1, err := name.NewTag("gcr.io/foo/bar:latest", name.StrictValidation)
177 if err != nil {
178 t.Fatalf("Error creating test tag1.")
179 }
180 tag2, err := name.NewTag("gcr.io/baz/bat:latest", name.StrictValidation)
181 if err != nil {
182 t.Fatalf("Error creating test tag2.")
183 }
184 dig3, err := name.NewDigest("gcr.io/baz/baz@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", name.StrictValidation)
185 if err != nil {
186 t.Fatalf("Error creating test dig3.")
187 }
188 refToImage := make(map[name.Reference]v1.Image)
189 refToImage[tag1] = randImage1
190 refToImage[tag2] = randImage2
191 refToImage[dig3] = randImage3
192
193 // Write both images to the tarball.
194 if err := tarball.MultiRefWriteToFile(fp.Name(), refToImage); err != nil {
195 t.Fatalf("Unexpected error writing tarball: %v", err)
196 }
197 for ref, img := range refToImage {
198 tag, ok := ref.(name.Tag)
199 if !ok {
200 continue
201 }
202
203 tarImage, err := tarball.ImageFromPath(fp.Name(), &tag)
204 if err != nil {

Callers

nothing calls this directly

Calls 9

ImageFunction · 0.92
NewTagFunction · 0.92
NewDigestFunction · 0.92
MultiRefWriteToFileFunction · 0.92
ImageFromPathFunction · 0.92
ImageFunction · 0.92
ImagesFunction · 0.92
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…