Skip to content

Commit

Permalink
Allow modifying the MediaType of a layer during mutate.Append. (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc committed Sep 1, 2020
1 parent ded15ea commit 071a121
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/v1/mutate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (i *image) compute() error {
desc.URLs = add.URLs
}

if add.MediaType != "" {
desc.MediaType = add.MediaType
}

manifestLayers = append(manifestLayers, *desc)
digestMap[desc.Digest] = add.Layer
}
Expand Down
1 change: 1 addition & 0 deletions pkg/v1/mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Addendum struct {
History v1.History
URLs []string
Annotations map[string]string
MediaType types.MediaType
}

// AppendLayers applies layers to a base image.
Expand Down
4 changes: 4 additions & 0 deletions pkg/v1/mutate/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestAppendWithAddendum(t *testing.T) {
Annotations: map[string]string{
"foo": "bar",
},
MediaType: types.MediaType("foo"),
}

result, err := mutate.Append(source, addendum)
Expand Down Expand Up @@ -181,6 +182,9 @@ func TestAppendWithAddendum(t *testing.T) {
if diff := cmp.Diff(m.Layers[1].Annotations, addendum.Annotations); diff != "" {
t.Fatalf("the appended Annotations is not the same (-got, +want) %s", diff)
}
if diff := cmp.Diff(m.Layers[1].MediaType, addendum.MediaType); diff != "" {
t.Fatalf("the appended MediaType is not the same (-got, +want) %s", diff)
}
}

func TestAppendLayers(t *testing.T) {
Expand Down

0 comments on commit 071a121

Please sign in to comment.