@@ -197,6 +197,7 @@ func TestBuildCommandMap(t *testing.T) {
197197 desc string
198198 idx v1.ImageIndex
199199 wantErr bool
200+ want map [string ][]string
200201 }{{
201202 // Valid multi-platform image even though some platforms only differ by variant or osversion.
202203 desc : "valid index" ,
@@ -226,6 +227,13 @@ func TestBuildCommandMap(t *testing.T) {
226227 Platform : & v1.Platform {OS : "windows" , Architecture : "amd64" , OSVersion : "4.5.6" },
227228 },
228229 }),
230+ want : map [string ][]string {
231+ "linux/amd64" : nil ,
232+ "linux/arm64/7" : nil ,
233+ "linux/arm64/8" : nil ,
234+ "windows/amd64:1.2.3" : nil ,
235+ "windows/amd64:4.5.6" : nil ,
236+ },
229237 }, {
230238 desc : "valid index, with dupes" ,
231239 idx : mutate .AppendManifests (empty .Index , mutate.IndexAddendum {
@@ -239,6 +247,9 @@ func TestBuildCommandMap(t *testing.T) {
239247 Platform : & v1.Platform {OS : "linux" , Architecture : "amd64" },
240248 },
241249 }),
250+ want : map [string ][]string {
251+ "linux/amd64" : nil ,
252+ },
242253 }, {
243254 desc : "invalid index, dupes with different digests" ,
244255 idx : mutate .AppendManifests (empty .Index , mutate.IndexAddendum {
@@ -253,13 +264,41 @@ func TestBuildCommandMap(t *testing.T) {
253264 },
254265 }),
255266 wantErr : true ,
267+ }, {
268+ desc : "valid index, with unknown platform" ,
269+ idx : mutate .AppendManifests (empty .Index , mutate.IndexAddendum {
270+ Add : img ,
271+ Descriptor : v1.Descriptor {
272+ Platform : & v1.Platform {OS : "linux" , Architecture : "amd64" },
273+ },
274+ }, mutate.IndexAddendum {
275+ Add : img ,
276+ Descriptor : v1.Descriptor {
277+ Platform : & v1.Platform {OS : "unknown" , Architecture : "unknown" },
278+ },
279+ }),
280+ want : map [string ][]string {
281+ "linux/amd64" : nil ,
282+ },
283+ }, {
284+ desc : "valid index, only unknown platform" ,
285+ idx : mutate .AppendManifests (empty .Index , mutate.IndexAddendum {
286+ Add : img ,
287+ Descriptor : v1.Descriptor {
288+ Platform : & v1.Platform {OS : "unknown" , Architecture : "unknown" },
289+ },
290+ }),
291+ want : map [string ][]string {},
256292 }} {
257293 t .Run (c .desc , func (t * testing.T ) {
258- _ , err := buildCommandMap (c .idx , true )
294+ got , err := buildCommandMap (c .idx , true )
259295 gotErr := (err != nil )
260296 if gotErr != c .wantErr {
261297 t .Fatalf ("got err: %v, want err: %t" , err , c .wantErr )
262298 }
299+ if d := cmp .Diff (c .want , got ); d != "" && ! c .wantErr {
300+ t .Errorf ("Diff %s" , diff .PrintWantGot (d ))
301+ }
263302 })
264303 }
265304}
0 commit comments