blob: 0ea1448fc01677b4753307b203d05874e3f8fae3 [file] [log] [blame]
Serge Bazanski504ea312023-03-22 17:47:48 +01001package main
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7)
8
9// TestTableLayout performs a smoke test of the table layout functionality.
10func TestTableLayout(t *testing.T) {
11 tab := table{}
12
13 e := entry{}
14 e.add("id", "short")
15 e.add("labels", "")
16 tab.add(e)
17
18 e = entry{}
19 e.add("whoops", "only in second")
20 e.add("labels", "bar")
21 e.add("id", "this one is a very long one")
22 tab.add(e)
23
24 e = entry{}
25 e.add("id", "normal length")
26 e.add("labels", "foo")
27 tab.add(e)
28
29 buf := bytes.NewBuffer(nil)
30 tab.print(buf, nil)
31
32 golden := `
33ID LABELS WHOOPS
34short
35this one is a very long one bar only in second
36normal length foo
37`
38 golden = strings.TrimSpace(golden)
39 got := strings.TrimSpace(buf.String())
40 if got != golden {
41 t.Logf("wanted: \n" + golden)
42 t.Logf("got: \n" + got)
43 t.Errorf("mismatch")
44 }
45}