github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/control/controldisplay/result_reason_test.go (about) 1 package controldisplay 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 type resultReasonTest struct { 9 status string 10 reason string 11 width int 12 expected string 13 } 14 15 func testCasesResultReason() map[string]resultReasonTest { 16 return map[string]resultReasonTest{ 17 "error fit": { 18 status: "error", 19 reason: "short error reason", 20 width: 100, 21 expected: fmt.Sprintf("%s", ControlColors.ReasonColors["error"]("short error reason ")), 22 }, 23 "ok fit": { 24 status: "ok", 25 reason: "short ok reason", 26 width: 100, 27 expected: fmt.Sprintf("%s", ControlColors.ReasonColors["ok"]("short ok reason ")), 28 }, 29 "error truncate": { 30 status: "error", 31 reason: "long error reason is very long and goes on and on", 32 width: 40, 33 expected: fmt.Sprintf("%s", ControlColors.ReasonColors["error"]("long error reason is very long and goe… ")), 34 }, 35 } 36 } 37 38 func TestResultReason(t *testing.T) { 39 themeDef := ColorSchemes["plain"] 40 scheme, _ := NewControlColorScheme(themeDef) 41 ControlColors = scheme 42 43 for name, test := range testCasesResultReason() { 44 output := NewResultReasonRenderer(test.status, test.reason, test.width).Render() 45 if output != test.expected { 46 t.Errorf("Test: '%s'' FAILED : \nexpected:\n %v \ngot:\n %v\n", name, test.expected, output) 47 } 48 } 49 }