TODO(cyx): think about whether we should extract this function in the `display` package. For now duplication might be better and less premature.
(t testing.TB, got string, header []string, data [][]string)
| 13 | // TODO(cyx): think about whether we should extract this function in the |
| 14 | // `display` package. For now duplication might be better and less premature. |
| 15 | func expectTable(t testing.TB, got string, header []string, data [][]string) { |
| 16 | w := &bytes.Buffer{} |
| 17 | |
| 18 | tableString := &strings.Builder{} |
| 19 | table := tablewriter.NewWriter(tableString) |
| 20 | table.SetHeader(header) |
| 21 | |
| 22 | table.SetAutoWrapText(false) |
| 23 | table.SetAutoFormatHeaders(true) |
| 24 | table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) |
| 25 | table.SetAlignment(tablewriter.ALIGN_LEFT) |
| 26 | table.SetCenterSeparator("") |
| 27 | table.SetColumnSeparator("") |
| 28 | table.SetRowSeparator("") |
| 29 | table.SetHeaderLine(false) |
| 30 | table.SetBorder(false) |
| 31 | |
| 32 | for _, v := range data { |
| 33 | table.Append(v) |
| 34 | } |
| 35 | |
| 36 | table.Render() |
| 37 | fmt.Fprint(w, tableString.String()) |
| 38 | |
| 39 | want := w.String() |
| 40 | |
| 41 | if got != want { |
| 42 | t.Fatal(cmp.Diff(want, got)) |
| 43 | } |
| 44 | } |
no outgoing calls
no test coverage detected