From ef87035bbb83de19a4ca8118c2a8a10675ea3721 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 3 Oct 2016 15:17:39 -0400 Subject: [PATCH] Generate api/types:Image from the swagger spec and rename it to a more appropriate name ImageSummary. Signed-off-by: Daniel Nephin --- command/formatter/disk_usage.go | 4 ++-- command/formatter/image.go | 8 ++++---- command/formatter/image_test.go | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/command/formatter/disk_usage.go b/command/formatter/disk_usage.go index acb210dbff..6f97d3b0f9 100644 --- a/command/formatter/disk_usage.go +++ b/command/formatter/disk_usage.go @@ -31,7 +31,7 @@ type DiskUsageContext struct { Context Verbose bool LayersSize int64 - Images []*types.Image + Images []*types.ImageSummary Containers []*types.Container Volumes []*types.Volume } @@ -155,7 +155,7 @@ func (ctx *DiskUsageContext) Write() { type diskUsageImagesContext struct { HeaderContext totalSize int64 - images []*types.Image + images []*types.ImageSummary } func (c *diskUsageImagesContext) Type() string { diff --git a/command/formatter/image.go b/command/formatter/image.go index 1e71bda3aa..594b2f3926 100644 --- a/command/formatter/image.go +++ b/command/formatter/image.go @@ -26,7 +26,7 @@ type ImageContext struct { Digest bool } -func isDangling(image types.Image) bool { +func isDangling(image types.ImageSummary) bool { return len(image.RepoTags) == 1 && image.RepoTags[0] == ":" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "@" } @@ -72,14 +72,14 @@ virtual_size: {{.Size}} } // ImageWrite writes the formatter images using the ImageContext -func ImageWrite(ctx ImageContext, images []types.Image) error { +func ImageWrite(ctx ImageContext, images []types.ImageSummary) error { render := func(format func(subContext subContext) error) error { return imageFormat(ctx, images, format) } return ctx.Write(&imageContext{}, render) } -func imageFormat(ctx ImageContext, images []types.Image, format func(subContext subContext) error) error { +func imageFormat(ctx ImageContext, images []types.ImageSummary, format func(subContext subContext) error) error { for _, image := range images { images := []*imageContext{} if isDangling(image) { @@ -184,7 +184,7 @@ func imageFormat(ctx ImageContext, images []types.Image, format func(subContext type imageContext struct { HeaderContext trunc bool - i types.Image + i types.ImageSummary repo string tag string digest string diff --git a/command/formatter/image_test.go b/command/formatter/image_test.go index 73b3c3f2e9..ffe77f6677 100644 --- a/command/formatter/image_test.go +++ b/command/formatter/image_test.go @@ -24,36 +24,36 @@ func TestImageContext(t *testing.T) { call func() string }{ {imageContext{ - i: types.Image{ID: imageID}, + i: types.ImageSummary{ID: imageID}, trunc: true, }, stringid.TruncateID(imageID), imageIDHeader, ctx.ID}, {imageContext{ - i: types.Image{ID: imageID}, + i: types.ImageSummary{ID: imageID}, trunc: false, }, imageID, imageIDHeader, ctx.ID}, {imageContext{ - i: types.Image{Size: 10, VirtualSize: 10}, + i: types.ImageSummary{Size: 10, VirtualSize: 10}, trunc: true, }, "10 B", sizeHeader, ctx.Size}, {imageContext{ - i: types.Image{Created: unix}, + i: types.ImageSummary{Created: unix}, trunc: true, }, time.Unix(unix, 0).String(), createdAtHeader, ctx.CreatedAt}, // FIXME // {imageContext{ - // i: types.Image{Created: unix}, + // i: types.ImageSummary{Created: unix}, // trunc: true, // }, units.HumanDuration(time.Unix(unix, 0)), createdSinceHeader, ctx.CreatedSince}, {imageContext{ - i: types.Image{}, + i: types.ImageSummary{}, repo: "busybox", }, "busybox", repositoryHeader, ctx.Repository}, {imageContext{ - i: types.Image{}, + i: types.ImageSummary{}, tag: "latest", }, "latest", tagHeader, ctx.Tag}, {imageContext{ - i: types.Image{}, + i: types.ImageSummary{}, digest: "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", }, "sha256:d149ab53f8718e987c3a3024bb8aa0e2caadf6c0328f1d9d850b2a2a67f2819a", digestHeader, ctx.Digest}, } @@ -262,7 +262,7 @@ image_id: imageID3 } for _, testcase := range cases { - images := []types.Image{ + images := []types.ImageSummary{ {ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime}, {ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: unixTime}, {ID: "imageID3", RepoTags: []string{":"}, RepoDigests: []string{"@"}, Created: unixTime}, @@ -280,7 +280,7 @@ image_id: imageID3 func TestImageContextWriteWithNoImage(t *testing.T) { out := bytes.NewBufferString("") - images := []types.Image{} + images := []types.ImageSummary{} contexts := []struct { context ImageContext