From b4c870f4ff6fdec76f9ef7d222b60e99db902865 Mon Sep 17 00:00:00 2001 From: jonjohnsonjr Date: Mon, 11 Jan 2021 12:07:00 -0800 Subject: [PATCH] Make gcrane ls --json output consistent (#888) This json.Number thing was added when AR was returning the wrong thing, now they are consistent, so we should be too. --- pkg/v1/google/list.go | 14 ++++----- pkg/v1/google/list_test.go | 58 -------------------------------------- 2 files changed, 6 insertions(+), 66 deletions(-) diff --git a/pkg/v1/google/list.go b/pkg/v1/google/list.go index cdc7d486a..52e525a90 100644 --- a/pkg/v1/google/list.go +++ b/pkg/v1/google/list.go @@ -105,14 +105,12 @@ func (l *lister) list(repo name.Repository) (*Tags, error) { return &tags, nil } -// Uploaded uses json.Number to work around GCR returning timeUploaded -// as a string, while AR returns the same field as int64. type rawManifestInfo struct { - Size string `json:"imageSizeBytes"` - MediaType string `json:"mediaType"` - Created string `json:"timeCreatedMs"` - Uploaded json.Number `json:"timeUploadedMs"` - Tags []string `json:"tag"` + Size string `json:"imageSizeBytes"` + MediaType string `json:"mediaType"` + Created string `json:"timeCreatedMs"` + Uploaded string `json:"timeUploadedMs"` + Tags []string `json:"tag"` } // ManifestInfo is a Manifests entry is the output of List and Walk. @@ -140,7 +138,7 @@ func (m ManifestInfo) MarshalJSON() ([]byte, error) { Size: strconv.FormatUint(m.Size, 10), MediaType: m.MediaType, Created: toUnixMs(m.Created), - Uploaded: json.Number(toUnixMs(m.Uploaded)), + Uploaded: toUnixMs(m.Uploaded), Tags: m.Tags, }) } diff --git a/pkg/v1/google/list_test.go b/pkg/v1/google/list_test.go index 191861757..709aaf97b 100644 --- a/pkg/v1/google/list_test.go +++ b/pkg/v1/google/list_test.go @@ -67,64 +67,6 @@ func TestRoundtrip(t *testing.T) { } } -// GCR returns timeUploaded as string -func TestTimeUploadedMsAsString(t *testing.T) { - data := []byte(` - { - "imageSizeBytes": "100", - "mediaType": "hi", - "tag": ["latest"], - "timeCreatedMs": "12345678", - "timeUploadedMs": "23456789" - } - `) - - raw := rawManifestInfo{} - if err := json.Unmarshal(data, &raw); err != nil { - t.Fatal(err) - } - - expectedRaw := rawManifestInfo{ - Size: "100", - MediaType: "hi", - Created: "12345678", - Uploaded: "23456789", - Tags: []string{"latest"}, - } - - if diff := cmp.Diff(expectedRaw, raw); diff != "" { - t.Errorf("Can't unmarshal rawManifestInfo with string timeUploadedMs: (-want +got) = %s", diff) - } -} - -// AR returns timeUploaded as int64, and timeCreatedMs is missing -func TestTimeUploadedMsAsInt64(t *testing.T) { - data := []byte(` - { - "imageSizeBytes": "100", - "mediaType": "hi", - "tag": ["latest"], - "timeUploadedMs": 23456789 - } - `) - - raw := rawManifestInfo{} - if err := json.Unmarshal(data, &raw); err != nil { - t.Fatal(err) - } - - expectedRaw := rawManifestInfo{ - Size: "100", - MediaType: "hi", - Uploaded: "23456789", - Tags: []string{"latest"}, - } - - if diff := cmp.Diff(expectedRaw, raw); diff != "" { - t.Errorf("Can't unmarshal rawManifestInfo with int64 timeUploadedMs: (-want +got) = %s", diff) - } -} - func TestList(t *testing.T) { cases := []struct { name string