From 4192a0259416e4e4c616cc1bce826767646c45ac Mon Sep 17 00:00:00 2001 From: Todd Trimble Date: Tue, 6 Oct 2020 22:41:44 -0400 Subject: [PATCH] Add info table tests (#985) * Add info table tests * Fix lint error about initialization --- view/info_table_test.go | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 view/info_table_test.go diff --git a/view/info_table_test.go b/view/info_table_test.go new file mode 100644 index 00000000..eb008644 --- /dev/null +++ b/view/info_table_test.go @@ -0,0 +1,44 @@ +package view + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func makeMap() map[string]string { + m := make(map[string]string) + m["foo"] = "val1" + m["bar"] = "val2" + m["baz"] = "val3" + + return m +} + +func newTestTable(height int) *InfoTable { + var headers [2]string + + headers[0] = "hdr0" + headers[1] = "hdr1" + + table := NewInfoTable( + headers[:], + makeMap(), + 1, + 1, + height, + ) + return table +} + +func Test_RenderSimpleInfoTable(t *testing.T) { + table := newTestTable(4).Render() + + assert.Equal(t, " ----- ------ \n HDR0 HDR1 \n ----- ------ \n bar val2 \n baz val3 \n foo val1 \n ----- ------ \n", table) +} + +func Test_RenderPaddedInfoTable(t *testing.T) { + table := newTestTable(6).Render() + + assert.Equal(t, " ----- ------ \n HDR0 HDR1 \n ----- ------ \n bar val2 \n baz val3 \n foo val1 \n \n \n ----- ------ \n", table) +}