(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestTaskContextWrite(t *testing.T) { |
| 18 | cases := []struct { |
| 19 | context formatter.Context |
| 20 | expected string |
| 21 | }{ |
| 22 | { |
| 23 | formatter.Context{Format: "{{InvalidFunction}}"}, |
| 24 | `template parsing error: template: :1: function "InvalidFunction" not defined`, |
| 25 | }, |
| 26 | { |
| 27 | formatter.Context{Format: "{{nil}}"}, |
| 28 | `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`, |
| 29 | }, |
| 30 | { |
| 31 | formatter.Context{Format: newTaskFormat("table", true)}, |
| 32 | `taskID1 |
| 33 | taskID2 |
| 34 | `, |
| 35 | }, |
| 36 | { |
| 37 | formatter.Context{Format: newTaskFormat("table {{.Name}}\t{{.Node}}\t{{.Ports}}", false)}, |
| 38 | string(golden.Get(t, "task-context-write-table-custom.golden")), |
| 39 | }, |
| 40 | { |
| 41 | formatter.Context{Format: newTaskFormat("table {{.Name}}", true)}, |
| 42 | `NAME |
| 43 | foobar_baz |
| 44 | foobar_bar |
| 45 | `, |
| 46 | }, |
| 47 | { |
| 48 | formatter.Context{Format: newTaskFormat("raw", true)}, |
| 49 | `id: taskID1 |
| 50 | id: taskID2 |
| 51 | `, |
| 52 | }, |
| 53 | { |
| 54 | formatter.Context{Format: newTaskFormat("{{.Name}} {{.Node}}", false)}, |
| 55 | `foobar_baz foo1 |
| 56 | foobar_bar foo2 |
| 57 | `, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | tasks := client.TaskListResult{ |
| 62 | Items: []swarm.Task{ |
| 63 | {ID: "taskID1"}, |
| 64 | {ID: "taskID2"}, |
| 65 | }, |
| 66 | } |
| 67 | names := map[string]string{ |
| 68 | "taskID1": "foobar_baz", |
| 69 | "taskID2": "foobar_bar", |
| 70 | } |
| 71 | nodes := map[string]string{ |
| 72 | "taskID1": "foo1", |
| 73 | "taskID2": "foo2", |
| 74 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…