libimage/manifests.list.Add(): preserve artifactType when all=true
When asked to add all of the entries from one index to another, don't forget to carry over the artifactType. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
parent
9520b232cc
commit
66b682ea98
|
|
@ -663,6 +663,9 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("adding instance with digest %q: %w", *instanceInfo.instanceDigest, err)
|
||||
}
|
||||
if err := l.List.SetArtifactType(instanceInfo.instanceDigest, instanceInfo.ArtifactType); err != nil {
|
||||
return "", fmt.Errorf("setting artifact manifest type for instance with digest %q: %w", *instanceInfo.instanceDigest, err)
|
||||
}
|
||||
if err = l.List.SetURLs(*instanceInfo.instanceDigest, instanceInfo.URLs); err != nil {
|
||||
return "", fmt.Errorf("setting URLs for instance with digest %q: %w", *instanceInfo.instanceDigest, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -816,3 +816,24 @@ func TestInstanceByImageAndFiles(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, []string{}, noFiles)
|
||||
}
|
||||
|
||||
// TestAddIndexOfArtifacts ensures that we don't fail to preserve artifactType
|
||||
// fields in artifact manifests when added from one list to another.
|
||||
func TestAddIndexOfArtifacts(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
absPath, err := filepath.Abs(filepath.Join("..", "..", "pkg", "manifests", "testdata", "artifacts", "index"))
|
||||
require.NoError(t, err)
|
||||
rawPath := "oci:" + absPath
|
||||
ref, err := alltransports.ParseImageName(rawPath)
|
||||
require.NoErrorf(t, err, "ParseImageName(%q)", rawPath)
|
||||
|
||||
cookedList := Create()
|
||||
_, err = cookedList.Add(ctx, sys, ref, true)
|
||||
assert.NoError(t, err, "list.Add()")
|
||||
|
||||
cooked := cookedList.OCIv1()
|
||||
for _, instance := range cooked.Manifests {
|
||||
assert.NotEmpty(t, instance.ArtifactType, "lost the artifactType field")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"layers": [
|
||||
{
|
||||
"digest": "sha256:541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53",
|
||||
"mediaType": "application/octet-stream",
|
||||
"size": 1000,
|
||||
"annotations": {
|
||||
"org.opencontainers.image.ref.name": "one-thousand"
|
||||
}
|
||||
}
|
||||
],
|
||||
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
||||
"artifactType": "application/vnd.reproducer+foo",
|
||||
"schemaVersion": 2
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"layers": [
|
||||
{
|
||||
"digest": "sha256:e6304a473c65ecd0ccffbd2f5925a8f51c44b11f59b66cfcc055e4bb911b8fa0",
|
||||
"mediaType": "application/octet-stream",
|
||||
"size": 500,
|
||||
"annotations": {
|
||||
"org.opencontainers.image.ref.name": "five-hundred"
|
||||
}
|
||||
}
|
||||
],
|
||||
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
||||
"artifactType": "application/vnd.reproducer+bar",
|
||||
"schemaVersion": 2
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"schemaVersion": 2,
|
||||
"mediaType": "application/vnd.oci.image.index.v1+json",
|
||||
"manifests": [
|
||||
{
|
||||
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
||||
"digest": "sha256:25cb16f769a2248cde5556529b88e3cdff322dbe5c71e40cfb24030221e88b06",
|
||||
"size": 417,
|
||||
"platform": {
|
||||
"architecture": "s390x",
|
||||
"os": "linux"
|
||||
},
|
||||
"artifactType": "application/vnd.reproducer+bar"
|
||||
},
|
||||
{
|
||||
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
||||
"digest": "sha256:11a1bc9fb43d6791f7f881a0375f88e83b10ea1c040a8d6d986cf799bb56e981",
|
||||
"size": 418,
|
||||
"platform": {
|
||||
"architecture": "ppc64le",
|
||||
"os": "linux"
|
||||
},
|
||||
"artifactType": "application/vnd.reproducer+foo"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"schemaVersion": 2,
|
||||
"mediaType": "application/vnd.oci.image.index.v1+json",
|
||||
"manifests": [
|
||||
{
|
||||
"mediaType": "application/vnd.oci.image.index.v1+json",
|
||||
"digest": "sha256:74c31168f466d846e0e0cf46fc8c14e0c516500558166654fce7555682b1cba6",
|
||||
"size": 760
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"imageLayoutVersion": "1.0.0"
|
||||
}
|
||||
Loading…
Reference in New Issue