MCPcopy Index your code
hub / github.com/docker/cli / TestContainerStatsContextWrite

Function TestContainerStatsContextWrite

cli/command/container/formatter_stats_test.go:186–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

184}
185
186func TestContainerStatsContextWrite(t *testing.T) {
187 tt := []struct {
188 context formatter.Context
189 expected string
190 }{
191 {
192 formatter.Context{Format: "{{InvalidFunction}}"},
193 `template parsing error: template: :1: function "InvalidFunction" not defined`,
194 },
195 {
196 formatter.Context{Format: "{{nil}}"},
197 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
198 },
199 {
200 formatter.Context{Format: "table {{.MemUsage}}"},
201 `MEM USAGE / LIMIT
20220B / 20B
203-- / --
204`,
205 },
206 {
207 formatter.Context{Format: "{{.Container}} {{.ID}} {{.Name}}"},
208 `container1 abcdef foo
209container2 --
210`,
211 },
212 {
213 formatter.Context{Format: "{{.Container}} {{.CPUPerc}}"},
214 `container1 20.00%
215container2 --
216`,
217 },
218 }
219
220 for _, te := range tt {
221 stats := []StatsEntry{
222 {
223 Container: "container1",
224 ID: "abcdef",
225 Name: "/foo",
226 CPUPercentage: 20,
227 Memory: 20,
228 MemoryLimit: 20,
229 MemoryPercentage: 20,
230 NetworkRx: 20,
231 NetworkTx: 20,
232 BlockRead: 20,
233 BlockWrite: 20,
234 PidsCurrent: 2,
235 IsInvalid: false,
236 },
237 {
238 Container: "container2",
239 CPUPercentage: 30,
240 Memory: 30,
241 MemoryLimit: 30,
242 MemoryPercentage: 30,
243 NetworkRx: 30,

Callers

nothing calls this directly

Calls 3

statsFormatWriteFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…