@@ -23,6 +23,7 @@ import (
2323
2424 "io/ioutil"
2525 "math/rand"
26+ "reflect"
2627 "runtime"
2728 "testing"
2829
@@ -94,11 +95,11 @@ func TestImport(t *testing.T) {
9495
9596 c1 , d2 := createConfig ()
9697
97- m1 , d3 := createManifest (c1 , [][]byte {b1 })
98+ m1 , d3 , expManifest := createManifest (c1 , [][]byte {b1 })
9899
99100 provider := client .ContentStore ()
100101
101- checkManifest := func (ctx context.Context , t * testing.T , d ocispec.Descriptor ) {
102+ checkManifest := func (ctx context.Context , t * testing.T , d ocispec.Descriptor , expManifest * ocispec. Manifest ) {
102103 m , err := images .Manifest (ctx , provider , d , nil )
103104 if err != nil {
104105 t .Fatalf ("unable to read target blob: %+v" , err )
@@ -115,6 +116,15 @@ func TestImport(t *testing.T) {
115116 if m .Layers [0 ].Digest != d1 {
116117 t .Fatalf ("unexpected layer hash %s, expected %s" , m .Layers [0 ].Digest , d1 )
117118 }
119+
120+ if expManifest != nil {
121+ if ! reflect .DeepEqual (m .Layers , expManifest .Layers ) {
122+ t .Fatalf ("DeepEqual on Layers failed: %v vs. %v" , m .Layers , expManifest .Layers )
123+ }
124+ if ! reflect .DeepEqual (m .Config , expManifest .Config ) {
125+ t .Fatalf ("DeepEqual on Config failed: %v vs. %v" , m .Config , expManifest .Config )
126+ }
127+ }
118128 }
119129
120130 for _ , tc := range []struct {
@@ -154,7 +164,7 @@ func TestImport(t *testing.T) {
154164 }
155165
156166 checkImages (t , imgs [0 ].Target .Digest , imgs , names ... )
157- checkManifest (ctx , t , imgs [0 ].Target )
167+ checkManifest (ctx , t , imgs [0 ].Target , nil )
158168 },
159169 },
160170 {
@@ -181,7 +191,7 @@ func TestImport(t *testing.T) {
181191 }
182192
183193 checkImages (t , d3 , imgs , names ... )
184- checkManifest (ctx , t , imgs [0 ].Target )
194+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
185195 },
186196 },
187197 {
@@ -202,7 +212,7 @@ func TestImport(t *testing.T) {
202212 }
203213
204214 checkImages (t , d3 , imgs , names ... )
205- checkManifest (ctx , t , imgs [0 ].Target )
215+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
206216 },
207217 Opts : []ImportOpt {
208218 WithImageRefTranslator (archive .AddRefPrefix ("localhost:5000/myimage" )),
@@ -226,7 +236,7 @@ func TestImport(t *testing.T) {
226236 }
227237
228238 checkImages (t , d3 , imgs , names ... )
229- checkManifest (ctx , t , imgs [0 ].Target )
239+ checkManifest (ctx , t , imgs [0 ].Target , expManifest )
230240 },
231241 Opts : []ImportOpt {
232242 WithImageRefTranslator (archive .FilterRefPrefix ("localhost:5000/myimage" )),
@@ -288,7 +298,7 @@ func createConfig() ([]byte, digest.Digest) {
288298 return b , digest .FromBytes (b )
289299}
290300
291- func createManifest (config []byte , layers [][]byte ) ([]byte , digest.Digest ) {
301+ func createManifest (config []byte , layers [][]byte ) ([]byte , digest.Digest , * ocispec. Manifest ) {
292302 manifest := ocispec.Manifest {
293303 Versioned : specs.Versioned {
294304 SchemaVersion : 2 ,
@@ -297,19 +307,25 @@ func createManifest(config []byte, layers [][]byte) ([]byte, digest.Digest) {
297307 MediaType : ocispec .MediaTypeImageConfig ,
298308 Digest : digest .FromBytes (config ),
299309 Size : int64 (len (config )),
310+ Annotations : map [string ]string {
311+ "ocispec" : "manifest.config.descriptor" ,
312+ },
300313 },
301314 }
302315 for _ , l := range layers {
303316 manifest .Layers = append (manifest .Layers , ocispec.Descriptor {
304317 MediaType : ocispec .MediaTypeImageLayer ,
305318 Digest : digest .FromBytes (l ),
306319 Size : int64 (len (l )),
320+ Annotations : map [string ]string {
321+ "ocispec" : "manifest.layers.descriptor" ,
322+ },
307323 })
308324 }
309325
310326 b , _ := json .Marshal (manifest )
311327
312- return b , digest .FromBytes (b )
328+ return b , digest .FromBytes (b ), & manifest
313329}
314330
315331func createIndex (manifest []byte , tags ... string ) []byte {
0 commit comments