(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestStackContextWrite(t *testing.T) { |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | format formatter.Format |
| 15 | expected string |
| 16 | }{ |
| 17 | { |
| 18 | name: "invalid function", |
| 19 | format: `{{InvalidFunction}}`, |
| 20 | expected: `template parsing error: template: :1: function "InvalidFunction" not defined`, |
| 21 | }, |
| 22 | { |
| 23 | name: "invalid placeholder", |
| 24 | format: `{{nil}}`, |
| 25 | expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`, |
| 26 | }, |
| 27 | { |
| 28 | name: "table format", |
| 29 | format: stackTableFormat, |
| 30 | expected: `NAME SERVICES |
| 31 | baz 2 |
| 32 | bar 1 |
| 33 | `, |
| 34 | }, |
| 35 | { |
| 36 | name: "custom table format", |
| 37 | format: `table {{.Name}}`, |
| 38 | expected: `NAME |
| 39 | baz |
| 40 | bar |
| 41 | `, |
| 42 | }, |
| 43 | { |
| 44 | name: "custom format", |
| 45 | format: `{{.Name}}`, |
| 46 | expected: `baz |
| 47 | bar |
| 48 | `, |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | for _, tc := range tests { |
| 53 | t.Run(tc.name, func(t *testing.T) { |
| 54 | var out bytes.Buffer |
| 55 | fmtCtx := formatter.Context{ |
| 56 | Format: tc.format, |
| 57 | Output: &out, |
| 58 | } |
| 59 | if err := stackWrite(fmtCtx, []stackSummary{ |
| 60 | {Name: "baz", Services: 2}, |
| 61 | {Name: "bar", Services: 1}, |
| 62 | }); err != nil { |
| 63 | assert.Error(t, err, tc.expected) |
| 64 | } else { |
| 65 | assert.Equal(t, out.String(), tc.expected) |
| 66 | } |
| 67 | }) |
| 68 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…