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

Function TestNodeContextWrite

cli/command/node/formatter_test.go:59–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestNodeContextWrite(t *testing.T) {
60 cases := []struct {
61 context formatter.Context
62 expected string
63 clusterInfo swarm.ClusterInfo
64 }{
65 // Errors
66 {
67 context: formatter.Context{Format: "{{InvalidFunction}}"},
68 expected: `template parsing error: template: :1: function "InvalidFunction" not defined`,
69 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
70 },
71 {
72 context: formatter.Context{Format: "{{nil}}"},
73 expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
74 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
75 },
76 // Table format
77 {
78 context: formatter.Context{Format: newFormat("table", false)},
79 expected: `ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
80nodeID1 foobar_baz Foo Drain Leader 18.03.0-ce
81nodeID2 foobar_bar Bar Active Reachable 1.2.3
82nodeID3 foobar_boo Boo Active ` + "\n", // (to preserve whitespace)
83 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
84 },
85 {
86 context: formatter.Context{Format: newFormat("table", true)},
87 expected: `nodeID1
88nodeID2
89nodeID3
90`,
91 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
92 },
93 {
94 context: formatter.Context{Format: newFormat("table {{.Hostname}}", false)},
95 expected: `HOSTNAME
96foobar_baz
97foobar_bar
98foobar_boo
99`,
100 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
101 },
102 {
103 context: formatter.Context{Format: newFormat("table {{.Hostname}}", true)},
104 expected: `HOSTNAME
105foobar_baz
106foobar_bar
107foobar_boo
108`,
109 clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
110 },
111 {
112 context: formatter.Context{Format: newFormat("table {{.ID}}\t{{.Hostname}}\t{{.TLSStatus}}", false)},
113 expected: `ID HOSTNAME TLS STATUS
114nodeID1 foobar_baz Needs Rotation
115nodeID2 foobar_bar Ready
116nodeID3 foobar_boo Unknown

Callers

nothing calls this directly

Calls 4

newFormatFunction · 0.70
formatWriteFunction · 0.70
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…