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

Function TestMultiWriteSameImage

pkg/legacy/tarball/write_test.go:91–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

89}
90
91func TestMultiWriteSameImage(t *testing.T) {
92 // Make a tempfile for tarball writes.
93 fp, err := os.CreateTemp("", "")
94 if err != nil {
95 t.Fatalf("Error creating temp file.")
96 }
97 t.Log(fp.Name())
98 defer fp.Close()
99 defer os.Remove(fp.Name())
100
101 // Make a random image
102 randImage, err := random.Image(256, 8)
103 if err != nil {
104 t.Fatalf("Error creating random image.")
105 }
106
107 // Make two tags that point to the random image above.
108 tag1, err := name.NewTag("gcr.io/foo/bar:latest", name.StrictValidation)
109 if err != nil {
110 t.Fatalf("Error creating test tag1.")
111 }
112 tag2, err := name.NewTag("gcr.io/baz/bat:latest", name.StrictValidation)
113 if err != nil {
114 t.Fatalf("Error creating test tag2.")
115 }
116 dig3, err := name.NewDigest("gcr.io/baz/baz@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", name.StrictValidation)
117 if err != nil {
118 t.Fatalf("Error creating test dig3.")
119 }
120 refToImage := make(map[name.Reference]v1.Image)
121 refToImage[tag1] = randImage
122 refToImage[tag2] = randImage
123 refToImage[dig3] = randImage
124
125 o, err := os.Create(fp.Name())
126 if err != nil {
127 t.Fatalf("Error creating %q to write image tarball: %v", fp.Name(), err)
128 }
129 defer o.Close()
130
131 // Write the images with both tags to the tarball
132 if err := MultiWrite(refToImage, o); err != nil {
133 t.Fatalf("Unexpected error writing tarball: %v", err)
134 }
135 for ref := range refToImage {
136 tag, ok := ref.(name.Tag)
137 if !ok {
138 continue
139 }
140
141 tarImage, err := tarball.ImageFromPath(fp.Name(), &tag)
142 if err != nil {
143 t.Fatalf("Unexpected error reading tarball: %v", err)
144 }
145 if err := validate.Image(tarImage); err != nil {
146 t.Errorf("validate.Image: %v", err)
147 }
148 if err := compare.Images(randImage, tarImage); err != nil {

Callers

nothing calls this directly

Calls 10

ImageFunction · 0.92
NewTagFunction · 0.92
NewDigestFunction · 0.92
ImageFromPathFunction · 0.92
ImageFunction · 0.92
ImagesFunction · 0.92
CreateMethod · 0.80
MultiWriteFunction · 0.70
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…