Merge pull request #30776 from WeiZhang555/stats-all-format-name-panic-cli
Fix panic of "docker stats --format {{.Name}} --all"
This commit is contained in:
commit
f5116c6802
2 changed files with 12 additions and 2 deletions
|
@ -149,8 +149,10 @@ func (c *containerStatsContext) Container() string {
|
||||||
|
|
||||||
func (c *containerStatsContext) Name() string {
|
func (c *containerStatsContext) Name() string {
|
||||||
c.AddHeader(nameHeader)
|
c.AddHeader(nameHeader)
|
||||||
name := c.s.Name[1:]
|
if len(c.s.Name) > 1 {
|
||||||
return name
|
return c.s.Name[1:]
|
||||||
|
}
|
||||||
|
return "--"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *containerStatsContext) ID() string {
|
func (c *containerStatsContext) ID() string {
|
||||||
|
|
|
@ -70,6 +70,12 @@ func TestContainerStatsContextWrite(t *testing.T) {
|
||||||
`MEM USAGE / LIMIT
|
`MEM USAGE / LIMIT
|
||||||
20B / 20B
|
20B / 20B
|
||||||
-- / --
|
-- / --
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Context{Format: "{{.Container}} {{.ID}} {{.Name}}"},
|
||||||
|
`container1 abcdef foo
|
||||||
|
container2 --
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -84,6 +90,8 @@ container2 --
|
||||||
stats := []StatsEntry{
|
stats := []StatsEntry{
|
||||||
{
|
{
|
||||||
Container: "container1",
|
Container: "container1",
|
||||||
|
ID: "abcdef",
|
||||||
|
Name: "/foo",
|
||||||
CPUPercentage: 20,
|
CPUPercentage: 20,
|
||||||
Memory: 20,
|
Memory: 20,
|
||||||
MemoryLimit: 20,
|
MemoryLimit: 20,
|
||||||
|
|
Loading…
Reference in a new issue