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

Function TestServiceContextWrite

cli/command/service/formatter_test.go:21–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestServiceContextWrite(t *testing.T) {
22 var (
23 // we need a pair of variables for setting the job parameters, because
24 // those parameters take pointers to uint64, which we can't make as a
25 // literal
26 varThree uint64 = 3
27 varTen uint64 = 10
28 )
29 cases := []struct {
30 context formatter.Context
31 expected string
32 }{
33 // Errors
34 {
35 formatter.Context{Format: "{{InvalidFunction}}"},
36 `template parsing error: template: :1: function "InvalidFunction" not defined`,
37 },
38 {
39 formatter.Context{Format: "{{nil}}"},
40 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
41 },
42 // Table format
43 {
44 formatter.Context{Format: NewListFormat("table", false)},
45 `ID NAME MODE REPLICAS IMAGE PORTS
4602_bar bar replicated 2/4 *:80->8090/udp
4701_baz baz global 1/3 *:80->8080/tcp
4804_qux2 qux2 replicated 3/3 (max 2 per node)
4903_qux10 qux10 replicated 2/3 (max 1 per node)
5005_job1 zarp1 replicated job 2/3 (5/10 completed)
5106_job2 zarp2 global job 1/1 (3/4 completed)
52`,
53 },
54 {
55 formatter.Context{Format: NewListFormat("table", true)},
56 `02_bar
5701_baz
5804_qux2
5903_qux10
6005_job1
6106_job2
62`,
63 },
64 {
65 formatter.Context{Format: NewListFormat("table {{.Name}}\t{{.Mode}}", false)},
66 `NAME MODE
67bar replicated
68baz global
69qux2 replicated
70qux10 replicated
71zarp1 replicated job
72zarp2 global job
73`,
74 },
75 {
76 formatter.Context{Format: NewListFormat("table {{.Name}}", true)},
77 `NAME
78bar

Callers

nothing calls this directly

Calls 5

NewListFormatFunction · 0.85
ListFormatWriteFunction · 0.85
GetMethod · 0.65
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…