diff --git a/pkg/crane/example_test.go b/pkg/crane/example_test.go index 3a6c18297..37201474a 100644 --- a/pkg/crane/example_test.go +++ b/pkg/crane/example_test.go @@ -27,5 +27,5 @@ func Example() { i, _ := crane.Image(c) d, _ := i.Digest() fmt.Println(d) - // Output: sha256:09fb0c6289cefaad8c74c7e5fd6758ad6906ab8f57f1350d9f4eb5a7df45ff8b + // Output: sha256:5c151b89fd9f3b93d910d05fb9f5efdf0fab8e645f65bbc268f926d64b15fc96 } diff --git a/pkg/crane/filemap_test.go b/pkg/crane/filemap_test.go index 21d8d54a6..6624ddeac 100644 --- a/pkg/crane/filemap_test.go +++ b/pkg/crane/filemap_test.go @@ -131,20 +131,20 @@ func TestImage(t *testing.T) { Digest string }{{ Name: "Empty contents", - Digest: "sha256:98132f58b523c391a5788997327cac95e114e3a6609d01163189774510705399", + Digest: "sha256:5b19422c75ffd2fe40e5cf332959491f16efd4948e5a647dfa18ef0893f60879", }, { Name: "One file", FileMap: map[string][]byte{ "/test": []byte("testy"), }, - Digest: "sha256:d905c03ac635172a96c12b8af6c90cfd028e3edaa3114b31a9e196ab38c16963", + Digest: "sha256:0a5a9b92cb817d5362b14d92173e9c2fb813a17f261a6ad55e6a952edf86f21a", }, { Name: "Two files", FileMap: map[string][]byte{ "/test": []byte("testy"), "/bar": []byte("not useful"), }, - Digest: "sha256:20e7e4800e5eb167f170970936c08d9e1bcbe91372420eeb6ab8d1a07752c3a3", + Digest: "sha256:d2c82c35a82be1186df962cd85b0eb1ac71f34ff2b9dab125b976cccbf11016c", }, { Name: "Many files", FileMap: map[string][]byte{ @@ -158,7 +158,7 @@ func TestImage(t *testing.T) { "/8": []byte("8"), "/9": []byte("9"), }, - Digest: "sha256:dfca2803510c8e3b83a3151f7c035c60cfa2a8a52465b802e18b85014de361f1", + Digest: "sha256:9fd84648d36fe2792dfa1b1fadb6ddb31ae0ade5154536013fd912e2ab424616", }} for _, tc := range tcs { t.Run(tc.Name, func(t *testing.T) { diff --git a/pkg/v1/empty/index.go b/pkg/v1/empty/index.go index 18b414891..ec3f85d70 100644 --- a/pkg/v1/empty/index.go +++ b/pkg/v1/empty/index.go @@ -45,7 +45,7 @@ func (i emptyIndex) IndexManifest() (*v1.IndexManifest, error) { } func (i emptyIndex) RawManifest() ([]byte, error) { - return json.Marshal(base()) + return json.MarshalIndent(base(), "", " ") } func (i emptyIndex) Image(v1.Hash) (v1.Image, error) { diff --git a/pkg/v1/mutate/image.go b/pkg/v1/mutate/image.go index 3ea27fe47..54526466c 100644 --- a/pkg/v1/mutate/image.go +++ b/pkg/v1/mutate/image.go @@ -257,7 +257,7 @@ func (i *image) RawManifest() ([]byte, error) { if err := i.compute(); err != nil { return nil, err } - return json.Marshal(i.manifest) + return json.MarshalIndent(i.manifest, "", " ") } // LayerByDigest returns a Layer for interacting with a particular layer of diff --git a/pkg/v1/mutate/index.go b/pkg/v1/mutate/index.go index 512effef6..952503b81 100644 --- a/pkg/v1/mutate/index.go +++ b/pkg/v1/mutate/index.go @@ -208,7 +208,7 @@ func (i *index) RawManifest() ([]byte, error) { if err := i.compute(); err != nil { return nil, err } - return json.Marshal(i.manifest) + return json.MarshalIndent(i.manifest, "", " ") } func (i *index) Manifests() ([]partial.Describable, error) { diff --git a/pkg/v1/mutate/mutate.go b/pkg/v1/mutate/mutate.go index 4207740c3..d1e880278 100644 --- a/pkg/v1/mutate/mutate.go +++ b/pkg/v1/mutate/mutate.go @@ -207,7 +207,7 @@ func (a arbitraryRawManifest) RawManifest() ([]byte, error) { if a.subject != nil { m["subject"] = a.subject } - return json.Marshal(m) + return json.MarshalIndent(m, "", " ") } // ConfigFile mutates the provided v1.Image to have the provided v1.ConfigFile diff --git a/pkg/v1/mutate/mutate_test.go b/pkg/v1/mutate/mutate_test.go index 17c8ee990..2cce52d15 100644 --- a/pkg/v1/mutate/mutate_test.go +++ b/pkg/v1/mutate/mutate_test.go @@ -285,15 +285,39 @@ func TestAnnotations(t *testing.T) { }{{ desc: "image", in: empty.Image, - want: `{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.docker.container.image.v1+json","size":115,"digest":"sha256:5b943e2b943f6c81dbbd4e2eca5121f4fcc39139e3d1219d6d89bd925b77d9fe"},"layers":[],"annotations":{"foo":"bar"}}`, + want: `{ + "schemaVersion": 2, + "mediaType": "application/vnd.docker.distribution.manifest.v2+json", + "config": { + "mediaType": "application/vnd.docker.container.image.v1+json", + "size": 115, + "digest": "sha256:5b943e2b943f6c81dbbd4e2eca5121f4fcc39139e3d1219d6d89bd925b77d9fe" + }, + "layers": [], + "annotations": { + "foo": "bar" + } +}`, }, { desc: "index", in: empty.Index, - want: `{"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":[],"annotations":{"foo":"bar"}}`, + want: `{ + "schemaVersion": 2, + "mediaType": "application/vnd.oci.image.index.v1+json", + "manifests": [], + "annotations": { + "foo": "bar" + } +}`, }, { desc: "arbitrary", in: arbitrary{}, - want: `{"annotations":{"foo":"bar"},"hello":"world"}`, + want: `{ + "annotations": { + "foo": "bar" + }, + "hello": "world" +}`, }} { t.Run(c.desc, func(t *testing.T) { got, err := mutate.Annotations(c.in, anns).RawManifest() @@ -511,7 +535,7 @@ func TestAppendStreamableLayer(t *testing.T) { if err != nil { t.Errorf("Digest: %v", err) } - wantDigest := "sha256:14d140947afedc6901b490265a08bc8ebe7f9d9faed6fdf19a451f054a7dd746" + wantDigest := "sha256:77007fcd3426ae84eb97d4aeb30a645fd68d2ea1eb1ef6b6acf1e10732cbc863" if h.String() != wantDigest { t.Errorf("Image digest got %q, want %q", h, wantDigest) } diff --git a/pkg/v1/partial/with.go b/pkg/v1/partial/with.go index c8b22b3f9..bd84f8cd0 100644 --- a/pkg/v1/partial/with.go +++ b/pkg/v1/partial/with.go @@ -178,7 +178,7 @@ func RawManifest(i WithManifest) ([]byte, error) { if err != nil { return nil, err } - return json.Marshal(m) + return json.MarshalIndent(m, "", " ") } // Size is a helper for implementing v1.Image diff --git a/pkg/v1/random/index.go b/pkg/v1/random/index.go index 4368bddff..8cc1d7be8 100644 --- a/pkg/v1/random/index.go +++ b/pkg/v1/random/index.go @@ -94,7 +94,7 @@ func (i *randomIndex) RawManifest() ([]byte, error) { if err != nil { return nil, err } - return json.Marshal(m) + return json.MarshalIndent(m, "", " ") } func (i *randomIndex) Image(h v1.Hash) (v1.Image, error) {