TestCopyWithPlatform verifies that Copy with WithPlatform resolves the multi-platform source index to the single requested manifest at the dst. Regression test for #2059.
(t *testing.T)
| 206 | // multi-platform source index to the single requested manifest at the dst. |
| 207 | // Regression test for #2059. |
| 208 | func TestCopyWithPlatform(t *testing.T) { |
| 209 | s := httptest.NewServer(registry.New()) |
| 210 | defer s.Close() |
| 211 | u, err := url.Parse(s.URL) |
| 212 | if err != nil { |
| 213 | t.Fatal(err) |
| 214 | } |
| 215 | src := path.Join(u.Host, "test/gcrane") + ":multi" |
| 216 | dst := path.Join(u.Host, "test/gcrane/copy") + ":amd64" |
| 217 | |
| 218 | amdImg, err := random.Image(1024, 2) |
| 219 | if err != nil { |
| 220 | t.Fatal(err) |
| 221 | } |
| 222 | armImg, err := random.Image(1024, 2) |
| 223 | if err != nil { |
| 224 | t.Fatal(err) |
| 225 | } |
| 226 | |
| 227 | idx := mutate.AppendManifests(empty.Index, |
| 228 | mutate.IndexAddendum{ |
| 229 | Add: amdImg, |
| 230 | Descriptor: v1.Descriptor{ |
| 231 | Platform: &v1.Platform{OS: "linux", Architecture: "amd64"}, |
| 232 | }, |
| 233 | }, |
| 234 | mutate.IndexAddendum{ |
| 235 | Add: armImg, |
| 236 | Descriptor: v1.Descriptor{ |
| 237 | Platform: &v1.Platform{OS: "linux", Architecture: "arm64"}, |
| 238 | }, |
| 239 | }, |
| 240 | ) |
| 241 | |
| 242 | srcRef, err := name.ParseReference(src) |
| 243 | if err != nil { |
| 244 | t.Fatal(err) |
| 245 | } |
| 246 | if err := remote.WriteIndex(srcRef, idx); err != nil { |
| 247 | t.Fatal(err) |
| 248 | } |
| 249 | |
| 250 | if err := Copy(src, dst, WithPlatform(&v1.Platform{OS: "linux", Architecture: "amd64"})); err != nil { |
| 251 | t.Fatal(err) |
| 252 | } |
| 253 | |
| 254 | dstRef, err := name.ParseReference(dst) |
| 255 | if err != nil { |
| 256 | t.Fatal(err) |
| 257 | } |
| 258 | desc, err := remote.Get(dstRef) |
| 259 | if err != nil { |
| 260 | t.Fatal(err) |
| 261 | } |
| 262 | if desc.MediaType.IsIndex() { |
| 263 | t.Fatalf("dst is an index (%s); expected a single-platform manifest", desc.MediaType) |
| 264 | } |
| 265 | amdDigest, err := amdImg.Digest() |
nothing calls this directly
no test coverage detected
searching dependent graphs…