(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func 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 |
| 80 | nodeID1 foobar_baz Foo Drain Leader 18.03.0-ce |
| 81 | nodeID2 foobar_bar Bar Active Reachable 1.2.3 |
| 82 | nodeID3 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 |
| 88 | nodeID2 |
| 89 | nodeID3 |
| 90 | `, |
| 91 | clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}}, |
| 92 | }, |
| 93 | { |
| 94 | context: formatter.Context{Format: newFormat("table {{.Hostname}}", false)}, |
| 95 | expected: `HOSTNAME |
| 96 | foobar_baz |
| 97 | foobar_bar |
| 98 | foobar_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 |
| 105 | foobar_baz |
| 106 | foobar_bar |
| 107 | foobar_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 |
| 114 | nodeID1 foobar_baz Needs Rotation |
| 115 | nodeID2 foobar_bar Ready |
| 116 | nodeID3 foobar_boo Unknown |
nothing calls this directly
no test coverage detected
searching dependent graphs…