Skip to content

Commit b931493

Browse files
committed
cli/command/container: improve TestContainerStatsContext
- Use sub-tests - Don't use un-named keys - Add test-cases for 'Name', 'ID' and custom container names Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b8cda96 commit b931493

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

cli/command/container/formatter_stats_test.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"testing"
66

77
"github.com/docker/cli/cli/command/formatter"
8-
"github.com/docker/cli/internal/test"
98
"gotest.tools/v3/assert"
109
is "gotest.tools/v3/assert/cmp"
1110
)
1211

1312
func TestContainerStatsContext(t *testing.T) {
14-
containerID := test.RandomID()
13+
const actorID = "c74518277ddc15a6afeaaeb06ee5f7433dcb27188224777c1efa7df1e8766d65"
1514

1615
var ctx statsContext
1716
tests := []struct {
@@ -23,12 +22,47 @@ func TestContainerStatsContext(t *testing.T) {
2322
call func() string
2423
}{
2524
{
26-
name: "Container",
27-
stats: StatsEntry{Container: containerID},
28-
expValue: containerID,
25+
name: "Container id",
26+
stats: StatsEntry{ID: actorID, Container: actorID},
27+
expValue: actorID,
2928
expHeader: containerHeader,
3029
call: ctx.Container,
3130
},
31+
{
32+
name: "Container name",
33+
stats: StatsEntry{ID: actorID, Container: "a-long-container-name"},
34+
expValue: "a-long-container-name",
35+
expHeader: containerHeader,
36+
call: ctx.Container,
37+
},
38+
{
39+
name: "ID",
40+
stats: StatsEntry{ID: actorID},
41+
expValue: actorID,
42+
expHeader: formatter.ContainerIDHeader,
43+
call: ctx.ID,
44+
},
45+
{
46+
name: "Name",
47+
stats: StatsEntry{Name: "/container-name"},
48+
expValue: "container-name",
49+
expHeader: formatter.ContainerIDHeader,
50+
call: ctx.Name,
51+
},
52+
{
53+
name: "Name empty",
54+
stats: StatsEntry{Name: ""},
55+
expValue: "--",
56+
expHeader: formatter.ContainerIDHeader,
57+
call: ctx.Name,
58+
},
59+
{
60+
name: "Name prefix only",
61+
stats: StatsEntry{Name: "/"},
62+
expValue: "--",
63+
expHeader: formatter.ContainerIDHeader,
64+
call: ctx.Name,
65+
},
3266
{
3367
name: "CPUPerc",
3468
stats: StatsEntry{CPUPercentage: 5.5},

0 commit comments

Comments
 (0)