(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func 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 |
| 46 | 02_bar bar replicated 2/4 *:80->8090/udp |
| 47 | 01_baz baz global 1/3 *:80->8080/tcp |
| 48 | 04_qux2 qux2 replicated 3/3 (max 2 per node) |
| 49 | 03_qux10 qux10 replicated 2/3 (max 1 per node) |
| 50 | 05_job1 zarp1 replicated job 2/3 (5/10 completed) |
| 51 | 06_job2 zarp2 global job 1/1 (3/4 completed) |
| 52 | `, |
| 53 | }, |
| 54 | { |
| 55 | formatter.Context{Format: NewListFormat("table", true)}, |
| 56 | `02_bar |
| 57 | 01_baz |
| 58 | 04_qux2 |
| 59 | 03_qux10 |
| 60 | 05_job1 |
| 61 | 06_job2 |
| 62 | `, |
| 63 | }, |
| 64 | { |
| 65 | formatter.Context{Format: NewListFormat("table {{.Name}}\t{{.Mode}}", false)}, |
| 66 | `NAME MODE |
| 67 | bar replicated |
| 68 | baz global |
| 69 | qux2 replicated |
| 70 | qux10 replicated |
| 71 | zarp1 replicated job |
| 72 | zarp2 global job |
| 73 | `, |
| 74 | }, |
| 75 | { |
| 76 | formatter.Context{Format: NewListFormat("table {{.Name}}", true)}, |
| 77 | `NAME |
| 78 | bar |
nothing calls this directly
no test coverage detected
searching dependent graphs…