@@ -23,6 +23,7 @@ import (
2323
2424 "io/ioutil"
2525 "math/rand"
26+ "reflect"
2627 "runtime"
2728 "testing"
2829
@@ -95,11 +96,11 @@ func TestImport(t *testing.T) {
9596
9697 c1 , d2 := createConfig ()
9798
98- m1 , d3 := createManifest (c1 , [][]byte {b1 })
99+ m1 , d3 , expManifest := createManifest (c1 , [][]byte {b1 })
99100
100101 provider := client .ContentStore ()
101102
102- checkManifest := func (ctx context.Context , t * testing.T , d ocispec.Descriptor ) {
103+ checkManifest := func (ctx context.Context , t * testing.T , d ocispec.Descriptor , expManifest * ocispec. Manifest ) {
103104 m , err := images .Manifest (ctx , provider , d , nil )
104105 if err != nil {
105106 t .Fatalf ("unable to read target blob: %+v" , err )
@@ -116,6 +117,15 @@ func TestImport(t *testing.T) {
116117 if m .Layers [0 ].Digest != d1 {
117118 t .Fatalf ("unexpected layer hash %s, expected %s" , m .Layers [0 ].Digest , d1 )
118119 }
120+
121+ if expManifest != nil {
122+ if ! reflect .DeepEqual (m .Layers , expManifest .Layers ) {
123+ t .Fatalf ("DeepEqual on Layers failed: %v vs. %v" , m .Layers , expManifest .Layers )
124+ }
125+ if ! reflect .DeepEqual (m .Config , expManifest .Config ) {
126+ t .Fatalf ("DeepEqual on Config failed: %v vs. %v" , m .Config , expManifest .Config )
127+ }
128+ }
119129 }
120130
121131 for _ , tc := range []struct {
@@ -155,7 +165,7 @@ func TestImport(t *testing.T) {
155165 }
156166
157167 checkImages (t , imgs [0 ].Target .Digest , imgs , names ... )
158- checkManifest (ctx , t , imgs [0 ].Target )
168+ checkManifest (ctx , t , imgs [0 ].Target , nil )
159169 },
160170 },
161171 {
@@ -182,7 +192,7 @@ func TestImport(t *testing.T) {
182192 }
183193
184194 checkImages (t , d3 , imgs , names ... )
185- checkManifest (ctx , t , imgs [0 ].Target )
195+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
186196 },
187197 },
188198 {
@@ -203,7 +213,7 @@ func TestImport(t *testing.T) {
203213 }
204214
205215 checkImages (t , d3 , imgs , names ... )
206- checkManifest (ctx , t , imgs [0 ].Target )
216+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
207217 },
208218 Opts : []ImportOpt {
209219 WithImageRefTranslator (archive .AddRefPrefix ("localhost:5000/myimage" )),
@@ -227,7 +237,7 @@ func TestImport(t *testing.T) {
227237 }
228238
229239 checkImages (t , d3 , imgs , names ... )
230- checkManifest (ctx , t , imgs [0 ].Target )
240+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
231241 },
232242 Opts : []ImportOpt {
233243 WithImageRefTranslator (archive .FilterRefPrefix ("localhost:5000/myimage" )),
@@ -289,7 +299,7 @@ func createConfig() ([]byte, digest.Digest) {
289299 return b , digest .FromBytes (b )
290300}
291301
292- func createManifest (config []byte , layers [][]byte ) ([]byte , digest.Digest ) {
302+ func createManifest (config []byte , layers [][]byte ) ([]byte , digest.Digest , * ocispec. Manifest ) {
293303 manifest := ocispec.Manifest {
294304 Versioned : specs.Versioned {
295305 SchemaVersion : 2 ,
@@ -298,19 +308,25 @@ func createManifest(config []byte, layers [][]byte) ([]byte, digest.Digest) {
298308 MediaType : ocispec .MediaTypeImageConfig ,
299309 Digest : digest .FromBytes (config ),
300310 Size : int64 (len (config )),
311+ Annotations : map [string ]string {
312+ "ocispec" : "manifest.config.descriptor" ,
313+ },
301314 },
302315 }
303316 for _ , l := range layers {
304317 manifest .Layers = append (manifest .Layers , ocispec.Descriptor {
305318 MediaType : ocispec .MediaTypeImageLayer ,
306319 Digest : digest .FromBytes (l ),
307320 Size : int64 (len (l )),
321+ Annotations : map [string ]string {
322+ "ocispec" : "manifest.layers.descriptor" ,
323+ },
308324 })
309325 }
310326
311327 b , _ := json .Marshal (manifest )
312328
313- return b , digest .FromBytes (b )
329+ return b , digest .FromBytes (b ), & manifest
314330}
315331
316332func createIndex (manifest []byte , tags ... string ) []byte {
0 commit comments