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

Function TestContainerContextWrite

cli/command/formatter/container_test.go:260–409  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestContainerContextWrite(t *testing.T) {
261 unixTime := time.Now().AddDate(0, 0, -1).Unix()
262 expectedTime := time.Unix(unixTime, 0).String()
263
264 cases := []struct {
265 context Context
266 expected string
267 }{
268 // Errors
269 {
270 context: Context{Format: "{{InvalidFunction}}"},
271 expected: `template parsing error: template: :1: function "InvalidFunction" not defined`,
272 },
273 {
274 context: Context{Format: "{{nil}}"},
275 expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
276 },
277 // Table Format
278 {
279 context: Context{Format: NewContainerFormat("table", false, true)},
280 expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
281containerID1 ubuntu "" 24 hours ago foobar_baz 0B
282containerID2 ubuntu "" 24 hours ago foobar_bar 0B
283`,
284 },
285 {
286 context: Context{Format: NewContainerFormat("table", false, false)},
287 expected: `CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
288containerID1 ubuntu "" 24 hours ago foobar_baz
289containerID2 ubuntu "" 24 hours ago foobar_bar
290`,
291 },
292 {
293 context: Context{Format: NewContainerFormat("table {{.Image}}", false, false)},
294 expected: "IMAGE\nubuntu\nubuntu\n",
295 },
296 {
297 context: Context{Format: NewContainerFormat("table {{.Image}}", false, true)},
298 expected: "IMAGE\nubuntu\nubuntu\n",
299 },
300 {
301 context: Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
302 expected: "containerID1\ncontainerID2\n",
303 },
304 {
305 context: Context{Format: NewContainerFormat("table", true, false)},
306 expected: "containerID1\ncontainerID2\n",
307 },
308 {
309 context: Context{Format: NewContainerFormat("table {{.State}}", false, true)},
310 expected: "STATE\nrunning\nrunning\n",
311 },
312 // Raw Format
313 {
314 context: Context{Format: NewContainerFormat("raw", false, false)},
315 expected: fmt.Sprintf(`container_id: containerID1
316image: ubuntu
317command: ""

Callers

nothing calls this directly

Calls 5

NewContainerFormatFunction · 0.85
ContainerWriteFunction · 0.85
StringMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…