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:
Sebastiaan van Stijn 2020-08-28 23:00:21 +02:00
parent f784262d07
commit dace8fdc75
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
51 changed files with 683 additions and 607 deletions

View File

@ -8,7 +8,6 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/swarm"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestConfigContextFormatWrite(t *testing.T) {
@ -53,13 +52,16 @@ id_rsa
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := FormatWrite(testcase.context, configs); err != nil {
assert.ErrorContains(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := FormatWrite(tc.context, configs); err != nil {
assert.ErrorContains(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(out.String(), testcase.expected))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -8,7 +8,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestDiffContextFormatWrite(t *testing.T) {
@ -48,14 +47,17 @@ D: /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("")
testcase.context.Output = out
err := DiffFormatWrite(testcase.context, diffs)
tc.context.Output = out
err := DiffFormatWrite(tc.context, diffs)
if err != nil {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -126,7 +126,7 @@ container2 --
}
func TestContainerStatsContextWriteWindows(t *testing.T) {
tt := []struct {
cases := []struct {
context formatter.Context
expected string
}{
@ -150,8 +150,6 @@ container2 -- --
`,
},
}
for _, te := range tt {
stats := []StatsEntry{
{
Container: "container1",
@ -180,21 +178,26 @@ container2 -- --
IsInvalid: true,
},
}
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
te.context.Output = &out
err := statsFormatWrite(te.context, stats, "windows", false)
tc.context.Output = &out
err := statsFormatWrite(tc.context, stats, "windows", false)
if err != nil {
assert.Error(t, err, te.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(te.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}
func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
var out bytes.Buffer
contexts := []struct {
cases := []struct {
context formatter.Context
expected string
}{
@ -221,18 +224,22 @@ func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
},
}
for _, context := range contexts {
statsFormatWrite(context.context, []StatsEntry{}, "linux", false)
assert.Check(t, is.Equal(context.expected, out.String()))
for _, tc := range cases {
tc := tc
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
out.Reset()
})
}
}
func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
var out bytes.Buffer
contexts := []struct {
cases := []struct {
context formatter.Context
expected string
}{
@ -259,11 +266,14 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
},
}
for _, context := range contexts {
statsFormatWrite(context.context, []StatsEntry{}, "windows", false)
assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
err := statsFormatWrite(tc.context, []StatsEntry{}, "windows", false)
assert.NilError(t, err)
assert.Equal(t, out.String(), tc.expected)
out.Reset()
})
}
}

View File

@ -248,19 +248,24 @@ size: 0B
},
}
for _, testcase := range cases {
containers := []types.Container{
{ID: "containerID1", Names: []string{"/foobar_baz"}, 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
err := ContainerWrite(testcase.context, containers)
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} 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("")
containers := []types.Container{}
contexts := []struct {
cases := []struct {
context Context
expected string
}{
@ -316,12 +321,15 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
},
}
for _, context := range contexts {
err := ContainerWrite(context.context, containers)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
err := ContainerWrite(tc.context, containers)
assert.NilError(t, err)
assert.Check(t, is.Equal(context.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
// Clean buffer
out.Reset()
})
}
}

View File

@ -5,7 +5,6 @@ import (
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
)
@ -107,13 +106,16 @@ Build Cache 0 0 0B
},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := testcase.context.Write(); err != nil {
assert.Check(t, is.Equal(testcase.expected, err.Error()))
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := tc.context.Write(); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -71,7 +71,7 @@ func (c *Context) parseFormat() (*template.Template, error) {
func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) {
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("")
tmpl.Funcs(templates.HeaderFunctions).Execute(buffer, subContext.FullHeader())
buffer.WriteTo(t)

View File

@ -299,20 +299,24 @@ image_id: imageID3
},
}
for _, testcase := range cases {
images := []types.ImageSummary{
{ID: "imageID1", RepoTags: []string{"image:tag1"}, RepoDigests: []string{"image@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf"}, Created: unixTime},
{ID: "imageID2", RepoTags: []string{"image:tag2"}, Created: zeroTime},
{ID: "imageID3", RepoTags: []string{"<none>:<none>"}, RepoDigests: []string{"<none>@<none>"}, Created: unixTime},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := ImageWrite(testcase.context, images)
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} 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("")
images := []types.ImageSummary{}
contexts := []struct {
cases := []struct {
context ImageContext
expected string
}{
@ -362,11 +366,14 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
},
}
for _, context := range contexts {
err := ImageWrite(context.context, images)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
err := ImageWrite(tc.context, images)
assert.NilError(t, err)
assert.Check(t, is.Equal(context.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
// Clean buffer
out.Reset()
})
}
}

View File

@ -59,7 +59,6 @@ func TestVolumeContextWrite(t *testing.T) {
context Context
expected string
}{
// Errors
{
Context{Format: "{{InvalidFunction}}"},
@ -125,19 +124,23 @@ foobar_bar
},
}
for _, testcase := range cases {
volumes := []*types.Volume{
{Name: "foobar_baz", Driver: "foo"},
{Name: "foobar_bar", Driver: "bar"},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := VolumeWrite(testcase.context, volumes)
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -12,7 +12,6 @@ import (
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/stringid"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip"
)
@ -201,7 +200,7 @@ imageID3 24 hours ago /bin/bash ls
imageID4 24 hours ago /bin/bash grep 183MB Hi
`
contexts := []struct {
cases := []struct {
context formatter.Context
expected string
}{
@ -221,10 +220,14 @@ imageID4 24 hours ago /bin/bash grep
},
}
for _, context := range contexts {
HistoryWrite(context.context, true, histories)
assert.Check(t, is.Equal(context.expected, out.String()))
for _, tc := range cases {
tc := tc
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
out.Reset()
})
}
}

View File

@ -155,19 +155,23 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
timestamp1, _ := time.Parse("2006-01-02", "2016-01-01")
timestamp2, _ := time.Parse("2006-01-02", "2017-01-01")
for _, testcase := range cases {
networks := []types.NetworkResource{
{ID: "networkID1", Name: "foobar_baz", Driver: "foo", Scope: "local", Created: timestamp1},
{ID: "networkID2", Name: "foobar_bar", Driver: "bar", Scope: "local", Created: timestamp2},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := FormatWrite(testcase.context, networks)
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -167,7 +167,6 @@ foobar_boo Unknown
},
}
for _, testcase := range cases {
nodes := []swarm.Node{
{
ID: "nodeID1",
@ -201,14 +200,20 @@ foobar_boo Unknown
Spec: swarm.NodeSpec{Availability: swarm.NodeAvailability("active")},
},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := FormatWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -125,19 +125,24 @@ foobar_bar
},
}
for _, testcase := range cases {
plugins := []*types.Plugin{
{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},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := FormatWrite(testcase.context, plugins)
for _, tc := range cases {
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 {
assert.Error(t, err, testcase.expected)
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -148,19 +148,24 @@ result2 5
},
}
for _, testcase := range cases {
results := []registrytypes.SearchResult{
{Name: "result1", Description: "Official build", StarCount: 5000, IsOfficial: true, IsAutomated: false},
{Name: "result2", Description: "Not official", StarCount: 5, IsOfficial: false, IsAutomated: true},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := SearchWrite(testcase.context, results)
for _, tc := range cases {
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 {
assert.Check(t, is.ErrorContains(err, testcase.expected))
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(out.String(), testcase.expected))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -8,7 +8,6 @@ import (
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types/swarm"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestSecretContextFormatWrite(t *testing.T) {
@ -53,13 +52,17 @@ id_rsa
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "id_rsa"}}},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
if err := FormatWrite(testcase.context, secrets); err != nil {
assert.Error(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := FormatWrite(tc.context, secrets); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -109,7 +109,6 @@ zarp2
},
}
for _, testcase := range cases {
services := []swarm.Service{
{
ID: "01_baz",
@ -221,14 +220,19 @@ zarp2
},
},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := ListFormatWrite(testcase.context, services)
if err != nil {
assert.Error(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := ListFormatWrite(tc.context, services); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -6,7 +6,6 @@ import (
"github.com/docker/cli/cli/command/formatter"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestStackContextWrite(t *testing.T) {
@ -61,14 +60,17 @@ bar
{Name: "baz", Services: 2, Orchestrator: "orchestrator1", Namespace: "namespace1"},
{Name: "bar", Services: 1, Orchestrator: "orchestrator2", Namespace: "namespace2"},
}
for _, testcase := range cases {
out := bytes.NewBufferString("")
testcase.context.Output = out
err := StackWrite(testcase.context, stacks)
if err != nil {
assert.Check(t, is.ErrorContains(err, testcase.expected))
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := StackWrite(tc.context, stacks); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(out.String(), testcase.expected))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -59,7 +59,6 @@ foobar_bar foo2
},
}
for _, testcase := range cases {
tasks := []swarm.Task{
{ID: "taskID1"},
{ID: "taskID2"},
@ -72,14 +71,19 @@ foobar_bar foo2
"taskID1": "foo1",
"taskID2": "foo2",
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := FormatWrite(testcase.context, tasks, names, nodes)
if err != nil {
assert.Error(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
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 {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}

View File

@ -118,20 +118,24 @@ tag3 bbbbbbbb
},
}
for _, testcase := range cases {
signedTags := []SignedTagInfo{
{Name: "tag1", Digest: "deadbeef", Signers: []string{"alice"}},
{Name: "tag2", Digest: "aaaaaaaa", Signers: []string{"alice", "bob"}},
{Name: "tag3", Digest: "bbbbbbbb", Signers: []string{}},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := TagWrite(testcase.context, signedTags)
if err != nil {
assert.Error(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := TagWrite(tc.context, signedTags); err != nil {
assert.Error(t, err, tc.expected)
} 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{
{Name: "alice", Keys: []string{"key11", "key12"}},
{Name: "bob", Keys: []string{"key21"}},
{Name: "eve", Keys: []string{"key31", "key32", "foobarbazquxquux"}},
}
out := bytes.NewBufferString("")
testcase.context.Output = out
err := SignerInfoWrite(testcase.context, signerInfo)
if err != nil {
assert.Error(t, err, testcase.expected)
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := SignerInfoWrite(tc.context, signerInfo); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Check(t, is.Equal(testcase.expected, out.String()))
assert.Equal(t, out.String(), tc.expected)
}
})
}
}