Skip to content

Commit

Permalink
Make gcrane ls --json output consistent (#888)
Browse files Browse the repository at this point in the history
This json.Number thing was added when AR was returning the wrong thing,
now they are consistent, so we should be too.
  • Loading branch information
jonjohnsonjr committed Jan 11, 2021
1 parent 8844390 commit b4c870f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 66 deletions.
14 changes: 6 additions & 8 deletions pkg/v1/google/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
})
}
Expand Down
58 changes: 0 additions & 58 deletions pkg/v1/google/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4c870f

Please sign in to comment.