blob: 5fca84c7125aee41349bb0b50089265188fab83b [file] [log] [blame]
Serge Bazanskie0c06172023-09-19 12:28:16 +00001package clitable
Serge Bazanski504ea312023-03-22 17:47:48 +01002
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) {
Serge Bazanskie0c06172023-09-19 12:28:16 +000011 tab := Table{}
Serge Bazanski504ea312023-03-22 17:47:48 +010012
Serge Bazanskie0c06172023-09-19 12:28:16 +000013 e := Entry{}
14 e.Add("id", "short")
15 e.Add("labels", "")
16 tab.Add(e)
Serge Bazanski504ea312023-03-22 17:47:48 +010017
Serge Bazanskie0c06172023-09-19 12:28:16 +000018 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)
Serge Bazanski504ea312023-03-22 17:47:48 +010023
Serge Bazanskie0c06172023-09-19 12:28:16 +000024 e = Entry{}
25 e.Add("id", "normal length")
26 e.Add("labels", "foo")
27 tab.Add(e)
Serge Bazanski504ea312023-03-22 17:47:48 +010028
29 buf := bytes.NewBuffer(nil)
Serge Bazanskie0c06172023-09-19 12:28:16 +000030 tab.Print(buf, nil)
Serge Bazanski504ea312023-03-22 17:47:48 +010031
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}