mirror of https://github.com/docker/cli.git
formatter: reduce minimum width for columns in table-view
The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f784262d07
commit
dace8fdc75
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigContextFormatWrite(t *testing.T) {
|
func TestConfigContextFormatWrite(t *testing.T) {
|
||||||
|
@ -53,13 +52,16 @@ id_rsa
|
||||||
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
|
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
|
||||||
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
|
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
|
||||||
}
|
}
|
||||||
for _, testcase := range cases {
|
for _, tc := range cases {
|
||||||
out := bytes.NewBufferString("")
|
tc := tc
|
||||||
testcase.context.Output = out
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
if err := FormatWrite(testcase.context, configs); err != nil {
|
var out bytes.Buffer
|
||||||
assert.ErrorContains(t, err, testcase.expected)
|
tc.context.Output = &out
|
||||||
|
if err := FormatWrite(tc.context, configs); err != nil {
|
||||||
|
assert.ErrorContains(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(out.String(), testcase.expected))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiffContextFormatWrite(t *testing.T) {
|
func TestDiffContextFormatWrite(t *testing.T) {
|
||||||
|
@ -48,14 +47,17 @@ D: /usr/app/old_app.js
|
||||||
{Kind: archive.ChangeDelete, Path: "/usr/app/old_app.js"},
|
{Kind: archive.ChangeDelete, Path: "/usr/app/old_app.js"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
for _, tc := range cases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
out := bytes.NewBufferString("")
|
out := bytes.NewBufferString("")
|
||||||
testcase.context.Output = out
|
tc.context.Output = out
|
||||||
err := DiffFormatWrite(testcase.context, diffs)
|
err := DiffFormatWrite(tc.context, diffs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ container2 --
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerStatsContextWriteWindows(t *testing.T) {
|
func TestContainerStatsContextWriteWindows(t *testing.T) {
|
||||||
tt := []struct {
|
cases := []struct {
|
||||||
context formatter.Context
|
context formatter.Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -150,8 +150,6 @@ container2 -- --
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, te := range tt {
|
|
||||||
stats := []StatsEntry{
|
stats := []StatsEntry{
|
||||||
{
|
{
|
||||||
Container: "container1",
|
Container: "container1",
|
||||||
|
@ -180,21 +178,26 @@ container2 -- --
|
||||||
IsInvalid: true,
|
IsInvalid: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
te.context.Output = &out
|
tc.context.Output = &out
|
||||||
err := statsFormatWrite(te.context, stats, "windows", false)
|
err := statsFormatWrite(tc.context, stats, "windows", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, te.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(te.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
|
func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
|
||||||
contexts := []struct {
|
cases := []struct {
|
||||||
context formatter.Context
|
context formatter.Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -221,18 +224,22 @@ func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range cases {
|
||||||
statsFormatWrite(context.context, []StatsEntry{}, "linux", false)
|
tc := tc
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
err := statsFormatWrite(tc.context, []StatsEntry{}, "linux", false)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
|
||||||
contexts := []struct {
|
cases := []struct {
|
||||||
context formatter.Context
|
context formatter.Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -259,11 +266,14 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range cases {
|
||||||
statsFormatWrite(context.context, []StatsEntry{}, "windows", false)
|
tc := tc
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
// Clean buffer
|
err := statsFormatWrite(tc.context, []StatsEntry{}, "windows", false)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
out.Reset()
|
out.Reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,19 +248,24 @@ size: 0B
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
containers := []types.Container{
|
containers := []types.Container{
|
||||||
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime, State: "running"},
|
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime, State: "running"},
|
||||||
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime, State: "running"},
|
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime, State: "running"},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := ContainerWrite(testcase.context, containers)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
err := ContainerWrite(tc.context, containers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +273,7 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
|
||||||
out := bytes.NewBufferString("")
|
out := bytes.NewBufferString("")
|
||||||
containers := []types.Container{}
|
containers := []types.Container{}
|
||||||
|
|
||||||
contexts := []struct {
|
cases := []struct {
|
||||||
context Context
|
context Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -316,12 +321,15 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range cases {
|
||||||
err := ContainerWrite(context.context, containers)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
err := ContainerWrite(tc.context, containers)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -107,13 +106,16 @@ Build Cache 0 0 0B
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
for _, tc := range cases {
|
||||||
out := bytes.NewBufferString("")
|
tc := tc
|
||||||
testcase.context.Output = out
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
if err := testcase.context.Write(); err != nil {
|
var out bytes.Buffer
|
||||||
assert.Check(t, is.Equal(testcase.expected, err.Error()))
|
tc.context.Output = &out
|
||||||
|
if err := tc.context.Write(); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (c *Context) parseFormat() (*template.Template, error) {
|
||||||
|
|
||||||
func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) {
|
func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) {
|
||||||
if c.Format.IsTable() {
|
if c.Format.IsTable() {
|
||||||
t := tabwriter.NewWriter(c.Output, 20, 1, 3, ' ', 0)
|
t := tabwriter.NewWriter(c.Output, 10, 1, 3, ' ', 0)
|
||||||
buffer := bytes.NewBufferString("")
|
buffer := bytes.NewBufferString("")
|
||||||
tmpl.Funcs(templates.HeaderFunctions).Execute(buffer, subContext.FullHeader())
|
tmpl.Funcs(templates.HeaderFunctions).Execute(buffer, subContext.FullHeader())
|
||||||
buffer.WriteTo(t)
|
buffer.WriteTo(t)
|
||||||
|
|
|
@ -299,20 +299,24 @@ image_id: imageID3
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
images := []types.ImageSummary{
|
images := []types.ImageSummary{
|
||||||
{ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime},
|
{ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime},
|
||||||
{ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: zeroTime},
|
{ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: zeroTime},
|
||||||
{ID: "imageID3", RepoTags: []string{"<none>:<none>"}, RepoDigests: []string{"<none>@<none>"}, Created: unixTime},
|
{ID: "imageID3", RepoTags: []string{"<none>:<none>"}, RepoDigests: []string{"<none>@<none>"}, Created: unixTime},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := ImageWrite(testcase.context, images)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
err := ImageWrite(tc.context, images)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +324,7 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
|
||||||
out := bytes.NewBufferString("")
|
out := bytes.NewBufferString("")
|
||||||
images := []types.ImageSummary{}
|
images := []types.ImageSummary{}
|
||||||
|
|
||||||
contexts := []struct {
|
cases := []struct {
|
||||||
context ImageContext
|
context ImageContext
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -362,11 +366,14 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range cases {
|
||||||
err := ImageWrite(context.context, images)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
err := ImageWrite(tc.context, images)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ func TestVolumeContextWrite(t *testing.T) {
|
||||||
context Context
|
context Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
Context{Format: "{{InvalidFunction}}"},
|
Context{Format: "{{InvalidFunction}}"},
|
||||||
|
@ -125,19 +124,23 @@ foobar_bar
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
volumes := []*types.Volume{
|
volumes := []*types.Volume{
|
||||||
{Name: "foobar_baz", Driver: "foo"},
|
{Name: "foobar_baz", Driver: "foo"},
|
||||||
{Name: "foobar_bar", Driver: "bar"},
|
{Name: "foobar_bar", Driver: "bar"},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := VolumeWrite(testcase.context, volumes)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
err := VolumeWrite(tc.context, volumes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/image"
|
"github.com/docker/docker/api/types/image"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
"gotest.tools/v3/skip"
|
"gotest.tools/v3/skip"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -201,7 +200,7 @@ imageID3 24 hours ago /bin/bash ls
|
||||||
imageID4 24 hours ago /bin/bash grep 183MB Hi
|
imageID4 24 hours ago /bin/bash grep 183MB Hi
|
||||||
`
|
`
|
||||||
|
|
||||||
contexts := []struct {
|
cases := []struct {
|
||||||
context formatter.Context
|
context formatter.Context
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
@ -221,10 +220,14 @@ imageID4 24 hours ago /bin/bash grep
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range cases {
|
||||||
HistoryWrite(context.context, true, histories)
|
tc := tc
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
err := HistoryWrite(tc.context, true, histories)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,19 +155,23 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
|
||||||
timestamp1, _ := time.Parse("2006-01-02", "2016-01-01")
|
timestamp1, _ := time.Parse("2006-01-02", "2016-01-01")
|
||||||
timestamp2, _ := time.Parse("2006-01-02", "2017-01-01")
|
timestamp2, _ := time.Parse("2006-01-02", "2017-01-01")
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
networks := []types.NetworkResource{
|
networks := []types.NetworkResource{
|
||||||
{ID: "networkID1", Name: "foobar_baz", Driver: "foo", Scope: "local", Created: timestamp1},
|
{ID: "networkID1", Name: "foobar_baz", Driver: "foo", Scope: "local", Created: timestamp1},
|
||||||
{ID: "networkID2", Name: "foobar_bar", Driver: "bar", Scope: "local", Created: timestamp2},
|
{ID: "networkID2", Name: "foobar_bar", Driver: "bar", Scope: "local", Created: timestamp2},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := FormatWrite(testcase.context, networks)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
err := FormatWrite(tc.context, networks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,6 @@ foobar_boo Unknown
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
nodes := []swarm.Node{
|
nodes := []swarm.Node{
|
||||||
{
|
{
|
||||||
ID: "nodeID1",
|
ID: "nodeID1",
|
||||||
|
@ -201,14 +200,20 @@ foobar_boo Unknown
|
||||||
Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("active")},
|
Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("active")},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := FormatWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
err := FormatWrite(tc.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &tc.clusterInfo}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,19 +125,24 @@ foobar_bar
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
plugins := []*types.Plugin{
|
plugins := []*types.Plugin{
|
||||||
{ID: "pluginID1", Name: "foobar_baz", Config: types.PluginConfig{Description: "description 1"}, Enabled: true},
|
{ID: "pluginID1", Name: "foobar_baz", Config: types.PluginConfig{Description: "description 1"}, Enabled: true},
|
||||||
{ID: "pluginID2", Name: "foobar_bar", Config: types.PluginConfig{Description: "description 2"}, Enabled: false},
|
{ID: "pluginID2", Name: "foobar_bar", Config: types.PluginConfig{Description: "description 2"}, Enabled: false},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := FormatWrite(testcase.context, plugins)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
err := FormatWrite(tc.context, plugins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,19 +148,24 @@ result2 5
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
results := []registrytypes.SearchResult{
|
results := []registrytypes.SearchResult{
|
||||||
{Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true, IsAutomated: false},
|
{Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true, IsAutomated: false},
|
||||||
{Name: "result2", Description: "Not official", StarCount: 5, IsOfficial: false, IsAutomated: true},
|
{Name: "result2", Description: "Not official", StarCount: 5, IsOfficial: false, IsAutomated: true},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := SearchWrite(testcase.context, results)
|
tc := tc
|
||||||
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
err := SearchWrite(tc.context, results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(out.String(), testcase.expected))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretContextFormatWrite(t *testing.T) {
|
func TestSecretContextFormatWrite(t *testing.T) {
|
||||||
|
@ -53,13 +52,17 @@ id_rsa
|
||||||
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
|
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
|
||||||
Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
|
Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
|
||||||
}
|
}
|
||||||
for _, testcase := range cases {
|
for _, tc := range cases {
|
||||||
out := bytes.NewBufferString("")
|
tc := tc
|
||||||
testcase.context.Output = out
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
if err := FormatWrite(testcase.context, secrets); err != nil {
|
var out bytes.Buffer
|
||||||
assert.Error(t, err, testcase.expected)
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
if err := FormatWrite(tc.context, secrets); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,6 @@ zarp2
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
services := []swarm.Service{
|
services := []swarm.Service{
|
||||||
{
|
{
|
||||||
ID: "01_baz",
|
ID: "01_baz",
|
||||||
|
@ -221,14 +220,19 @@ zarp2
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := ListFormatWrite(testcase.context, services)
|
tc := tc
|
||||||
if err != nil {
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
assert.Error(t, err, testcase.expected)
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
if err := ListFormatWrite(tc.context, services); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStackContextWrite(t *testing.T) {
|
func TestStackContextWrite(t *testing.T) {
|
||||||
|
@ -61,14 +60,17 @@ bar
|
||||||
{Name: "baz", Services: 2, Orchestrator: "orchestrator1", Namespace: "namespace1"},
|
{Name: "baz", Services: 2, Orchestrator: "orchestrator1", Namespace: "namespace1"},
|
||||||
{Name: "bar", Services: 1, Orchestrator: "orchestrator2", Namespace: "namespace2"},
|
{Name: "bar", Services: 1, Orchestrator: "orchestrator2", Namespace: "namespace2"},
|
||||||
}
|
}
|
||||||
for _, testcase := range cases {
|
for _, tc := range cases {
|
||||||
out := bytes.NewBufferString("")
|
tc := tc
|
||||||
testcase.context.Output = out
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
err := StackWrite(testcase.context, stacks)
|
var out bytes.Buffer
|
||||||
if err != nil {
|
tc.context.Output = &out
|
||||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
|
||||||
|
if err := StackWrite(tc.context, stacks); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(out.String(), testcase.expected))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,6 @@ foobar_bar foo2
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
tasks := []swarm.Task{
|
tasks := []swarm.Task{
|
||||||
{ID: "taskID1"},
|
{ID: "taskID1"},
|
||||||
{ID: "taskID2"},
|
{ID: "taskID2"},
|
||||||
|
@ -72,14 +71,19 @@ foobar_bar foo2
|
||||||
"taskID1": "foo1",
|
"taskID1": "foo1",
|
||||||
"taskID2": "foo2",
|
"taskID2": "foo2",
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := FormatWrite(testcase.context, tasks, names, nodes)
|
tc := tc
|
||||||
if err != nil {
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
assert.Error(t, err, testcase.expected)
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
if err := FormatWrite(tc.context, tasks, names, nodes); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,20 +118,24 @@ tag3 bbbbbbbb
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
signedTags := []SignedTagInfo{
|
signedTags := []SignedTagInfo{
|
||||||
{Name: "tag1", Digest: "deadbeef", Signers: []string{"alice"}},
|
{Name: "tag1", Digest: "deadbeef", Signers: []string{"alice"}},
|
||||||
{Name: "tag2", Digest: "aaaaaaaa", Signers: []string{"alice", "bob"}},
|
{Name: "tag2", Digest: "aaaaaaaa", Signers: []string{"alice", "bob"}},
|
||||||
{Name: "tag3", Digest: "bbbbbbbb", Signers: []string{}},
|
{Name: "tag3", Digest: "bbbbbbbb", Signers: []string{}},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
|
||||||
testcase.context.Output = out
|
for _, tc := range cases {
|
||||||
err := TagWrite(testcase.context, signedTags)
|
tc := tc
|
||||||
if err != nil {
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
assert.Error(t, err, testcase.expected)
|
var out bytes.Buffer
|
||||||
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
if err := TagWrite(tc.context, signedTags); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,19 +226,22 @@ eve foobarbazquxquux, key31, key32
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range cases {
|
|
||||||
signerInfo := []SignerInfo{
|
signerInfo := []SignerInfo{
|
||||||
{Name: "alice", Keys: []string{"key11", "key12"}},
|
{Name: "alice", Keys: []string{"key11", "key12"}},
|
||||||
{Name: "bob", Keys: []string{"key21"}},
|
{Name: "bob", Keys: []string{"key21"}},
|
||||||
{Name: "eve", Keys: []string{"key31", "key32", "foobarbazquxquux"}},
|
{Name: "eve", Keys: []string{"key31", "key32", "foobarbazquxquux"}},
|
||||||
}
|
}
|
||||||
out := bytes.NewBufferString("")
|
for _, tc := range cases {
|
||||||
testcase.context.Output = out
|
tc := tc
|
||||||
err := SignerInfoWrite(testcase.context, signerInfo)
|
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||||
if err != nil {
|
var out bytes.Buffer
|
||||||
assert.Error(t, err, testcase.expected)
|
tc.context.Output = &out
|
||||||
|
|
||||||
|
if err := SignerInfoWrite(tc.context, signerInfo); err != nil {
|
||||||
|
assert.Error(t, err, tc.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
assert.Equal(t, out.String(), tc.expected)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue