mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #30776 from WeiZhang555/stats-all-format-name-panic-cli
Fix panic of "docker stats --format {{.Name}} --all"
(cherry picked from commit f5116c6802
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
1c47c89d76
commit
e301d956b7
2 changed files with 12 additions and 2 deletions
|
@ -145,8 +145,10 @@ func (c *containerStatsContext) Container() string {
|
|||
|
||||
func (c *containerStatsContext) Name() string {
|
||||
c.AddHeader(nameHeader)
|
||||
name := c.s.Name[1:]
|
||||
return name
|
||||
if len(c.s.Name) > 1 {
|
||||
return c.s.Name[1:]
|
||||
}
|
||||
return "--"
|
||||
}
|
||||
|
||||
func (c *containerStatsContext) ID() string {
|
||||
|
|
|
@ -69,6 +69,12 @@ func TestContainerStatsContextWrite(t *testing.T) {
|
|||
`MEM USAGE / LIMIT
|
||||
20 B / 20 B
|
||||
-- / --
|
||||
`,
|
||||
},
|
||||
{
|
||||
Context{Format: "{{.Container}} {{.ID}} {{.Name}}"},
|
||||
`container1 abcdef foo
|
||||
container2 --
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
@ -83,6 +89,8 @@ container2 --
|
|||
stats := []StatsEntry{
|
||||
{
|
||||
Container: "container1",
|
||||
ID: "abcdef",
|
||||
Name: "/foo",
|
||||
CPUPercentage: 20,
|
||||
Memory: 20,
|
||||
MemoryLimit: 20,
|
||||
|
|
Loading…
Reference in a new issue