From d30c6d719a1566bdf7b113c8abaed76ed1b97ce5 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 19 Nov 2019 13:47:39 +0100 Subject: [PATCH] table minwidth is 20 set by cli/command/formatter/formatter.go#postFromat Signed-off-by: Nicolas De Loof --- e2e/images_test.go | 87 ++++++++++++++-------------- internal/commands/image/formatter.go | 7 ++- internal/commands/image/list_test.go | 32 ++++++---- 3 files changed, 70 insertions(+), 56 deletions(-) diff --git a/e2e/images_test.go b/e2e/images_test.go index c3af0f015..70278c0b7 100644 --- a/e2e/images_test.go +++ b/e2e/images_test.go @@ -66,11 +66,12 @@ func TestImageList(t *testing.T) { insertBundles(t, cmd) - expected := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago + expected := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]* ` + expectImageListOutput(t, cmd, expected) }) } @@ -87,10 +88,10 @@ func TestImageListDigests(t *testing.T) { runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) { cmd := info.configuredCmd insertBundles(t, cmd) - expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago + expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]* ` expectImageListDigestsOutput(t, cmd, expected) }) @@ -121,7 +122,7 @@ Deleted: b-simple-app:latest`, Err: `b-simple-app:latest: reference not found`, }) - expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME CREATED\n" + expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME CREATED \n" expectImageListOutput(t, cmd, expectedOutput) }) } @@ -139,8 +140,8 @@ func TestImageTag(t *testing.T) { cmd.Command = dockerCli.Command("app", "build", "--tag", "a-simple-app", filepath.Join("testdata", "simple")) icmd.RunCmd(cmd).Assert(t, icmd.Success) - singleImageExpectation := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago + singleImageExpectation := `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* ` expectImageListOutput(t, cmd, singleImageExpectation) @@ -189,63 +190,63 @@ a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago // tag image with only names dockerAppImageTag("a-simple-app", "b-simple-app") icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* `) // target tag dockerAppImageTag("a-simple-app", "a-simple-app:0.1") icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* `) // source tag dockerAppImageTag("a-simple-app:0.1", "c-simple-app") icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* `) // source and target tags dockerAppImageTag("a-simple-app:0.1", "b-simple-app:0.2") icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* `) // given a new application cmd.Command = dockerCli.Command("app", "build", "--tag", "push-pull", filepath.Join("testdata", "push-pull")) icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app 0.2 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]* `) // can be tagged to an existing tag dockerAppImageTag("push-pull", "b-simple-app:0.2") icmd.RunCmd(cmd).Assert(t, icmd.Success) - expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago -a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -b-simple-app 0.2 [a-f0-9]{12} push-pull [La-z0-9 ]+ ago -b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago -push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago + expectImageListOutput(t, cmd, `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +a-simple-app 0.1 [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +a-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +b-simple-app 0.2 [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]* +b-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +c-simple-app latest [a-f0-9]{12} simple [La-z0-9 ]+ ago[ ]* +push-pull latest [a-f0-9]{12} push-pull [La-z0-9 ]+ ago[ ]* `) }) } diff --git a/internal/commands/image/formatter.go b/internal/commands/image/formatter.go index 9863388b4..2a842cca3 100644 --- a/internal/commands/image/formatter.go +++ b/internal/commands/image/formatter.go @@ -10,9 +10,9 @@ import ( const ( defaultImageTableFormat = "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Name}}\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t" - defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}{{.Name}}\t\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t" + defaultImageTableFormatWithDigest = "table {{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.ID}}\t{{.Name}}\t\t{{if .CreatedSince }}{{.CreatedSince}}{{else}}N/A{{end}}\t" - imageIDHeader = "APP ID" + imageIDHeader = "APP IMAGE ID" repositoryHeader = "REPOSITORY" tagHeader = "TAG" digestHeader = "DIGEST" @@ -112,6 +112,9 @@ func (c *imageContext) Tag() string { } func (c *imageContext) Digest() string { + if c.i.Digest == "" { + return "" + } return c.i.Digest } diff --git a/internal/commands/image/list_test.go b/internal/commands/image/list_test.go index 7cd121991..3fe1e4d3e 100644 --- a/internal/commands/image/list_test.go +++ b/internal/commands/image/list_test.go @@ -83,21 +83,31 @@ func TestListCmd(t *testing.T) { }{ { name: "TestList", - expectedOutput: `REPOSITORY TAG APP IMAGE ID APP NAME CREATED -foo/bar 3f825b2d0657 Digested App -foo/bar 1.0 9aae408ee04f Foo App - a855ac937f2e Quiet App + expectedOutput: `REPOSITORY TAG APP IMAGE ID APP NAME CREATED +foo/bar 3f825b2d0657 Digested App N/A +foo/bar 1.0 9aae408ee04f Foo App N/A + a855ac937f2e Quiet App N/A `, - options: imageListOption{}, + options: imageListOption{format: "table"}, + }, + { + name: "TestTemplate", + expectedOutput: `APP IMAGE ID DIGEST +3f825b2d0657 sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 +9aae408ee04f +a855ac937f2e sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 +`, + options: imageListOption{format: "table {{.ID}}", digests: true}, }, { name: "TestListWithDigests", - expectedOutput: `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED -foo/bar sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 3f825b2d0657 Digested App -foo/bar 1.0 9aae408ee04f Foo App - sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 a855ac937f2e Quiet App + //nolint:lll + expectedOutput: `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME CREATED +foo/bar sha256:b59492bb814012ca3d2ce0b6728242d96b4af41687cc82166a4b5d7f2d9fb865 3f825b2d0657 Digested App N/A +foo/bar 1.0 9aae408ee04f Foo App N/A + sha256:a855ac937f2ed375ba4396bbc49c4093e124da933acd2713fb9bc17d7562a087 a855ac937f2e Quiet App N/A `, - options: imageListOption{digests: true}, + options: imageListOption{format: "table", digests: true}, }, { name: "TestListWithQuiet", @@ -105,7 +115,7 @@ foo/bar 1.0 9aae408ee04f a855ac937f2e `, - options: imageListOption{quiet: true}, + options: imageListOption{format: "table", quiet: true}, }, }