github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/group_title_test.go (about) 1 package controldisplay 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 type idTest struct { 9 id string 10 width int 11 expected string 12 } 13 14 func testCasesId() map[string]idTest { 15 return map[string]idTest{ 16 "shorter": { 17 id: "group title", 18 width: 100, 19 expected: fmt.Sprintf("%s", ControlColors.GroupTitle("group title ")), 20 }, 21 22 "equal": { 23 id: "group title", 24 width: 8, 25 expected: fmt.Sprintf("%s", ControlColors.GroupTitle("group … ")), 26 }, 27 "longer trim on space": { 28 id: "group title", 29 width: 7, 30 expected: fmt.Sprintf("%s", ControlColors.GroupTitle("group… ")), 31 }, 32 "longer trim on char": { 33 id: "group title", 34 width: 5, 35 expected: fmt.Sprintf("%s", ControlColors.GroupTitle("gro… ")), 36 }, 37 } 38 } 39 40 func TestId(t *testing.T) { 41 themeDef := ColorSchemes["plain"] 42 scheme, _ := NewControlColorScheme(themeDef) 43 ControlColors = scheme 44 45 for name, test := range testCasesId() { 46 renderer := NewGroupTitleRenderer(test.id, test.width) 47 output := renderer.Render() 48 49 if output != test.expected { 50 t.Errorf("Test: '%s'' FAILED : \nexpected:\n%s \ngot:\n%s\n", name, test.expected, output) 51 } 52 } 53 }