github.com/jfrog/frogbot/v2@v2.21.0/utils/outputwriter/simplifiedoutput_test.go (about) 1 package outputwriter 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestSimpleOutputFlags(t *testing.T) { 10 testCases := []struct { 11 name string 12 entitled bool 13 showCaColumn bool 14 }{ 15 {name: "entitled", entitled: true, showCaColumn: false}, 16 {name: "not entitled", entitled: false, showCaColumn: false}, 17 {name: "entitled with ca column", entitled: true, showCaColumn: true}, 18 {name: "not entitled with ca column", entitled: false, showCaColumn: true}, 19 } 20 for _, tc := range testCases { 21 t.Run(tc.name, func(t *testing.T) { 22 smo := &SimplifiedOutput{} 23 smo.SetJasOutputFlags(tc.entitled, tc.showCaColumn) 24 assert.Equal(t, tc.entitled, smo.entitledForJas) 25 assert.Equal(t, tc.showCaColumn, smo.showCaColumn) 26 assert.Equal(t, tc.entitled, smo.IsEntitledForJas()) 27 assert.Equal(t, tc.showCaColumn, smo.IsShowingCaColumn()) 28 }) 29 } 30 } 31 32 func TestSimpleSeparator(t *testing.T) { 33 smo := &SimplifiedOutput{} 34 assert.Equal(t, ", ", smo.Separator()) 35 } 36 37 func TestSimpleFormattedSeverity(t *testing.T) { 38 testCases := []struct { 39 name string 40 severity string 41 applicability string 42 expectedOutput string 43 }{ 44 { 45 name: "Applicable severity", 46 severity: "Low", 47 applicability: "Applicable", 48 expectedOutput: "Low", 49 }, 50 { 51 name: "Not applicable severity", 52 severity: "Medium", 53 applicability: "Not Applicable", 54 expectedOutput: "Medium", 55 }, 56 } 57 for _, tc := range testCases { 58 t.Run(tc.name, func(t *testing.T) { 59 smo := &SimplifiedOutput{} 60 assert.Equal(t, tc.expectedOutput, smo.FormattedSeverity(tc.severity, tc.applicability)) 61 }) 62 } 63 } 64 65 func TestSimpleImage(t *testing.T) { 66 testCases := []struct { 67 name string 68 source ImageSource 69 expectedOutput string 70 }{ 71 { 72 name: "no vulnerability pr banner", 73 source: NoVulnerabilityPrBannerSource, 74 expectedOutput: "**👍 Frogbot scanned this pull request and did not find any new security issues.**", 75 }, 76 { 77 name: "vulnerabilities pr banner", 78 source: VulnerabilitiesPrBannerSource, 79 expectedOutput: "**🚨 Frogbot scanned this pull request and found the below:**", 80 }, 81 { 82 name: "vulnerabilities fix pr banner", 83 source: VulnerabilitiesFixPrBannerSource, 84 expectedOutput: "**🚨 This automated pull request was created by Frogbot and fixes the below:**", 85 }, 86 } 87 for _, tc := range testCases { 88 t.Run(tc.name, func(t *testing.T) { 89 smo := &SimplifiedOutput{} 90 assert.Equal(t, tc.expectedOutput, smo.Image(tc.source)) 91 }) 92 } 93 } 94 95 func TestSimpleMarkInCenter(t *testing.T) { 96 testCases := []struct { 97 name string 98 content string 99 expectedOutput string 100 }{ 101 { 102 name: "empty content", 103 content: "", 104 expectedOutput: "", 105 }, 106 { 107 name: "non empty content", 108 content: "content", 109 expectedOutput: "content", 110 }, 111 } 112 for _, tc := range testCases { 113 t.Run(tc.name, func(t *testing.T) { 114 smo := &SimplifiedOutput{} 115 assert.Equal(t, tc.expectedOutput, smo.MarkInCenter(tc.content)) 116 }) 117 } 118 } 119 120 func TestSimpleMarkAsDetails(t *testing.T) { 121 testCases := []struct { 122 name string 123 summary string 124 content string 125 expectedOutput string 126 subTitleDepth int 127 }{ 128 { 129 name: "empty", 130 summary: "", 131 subTitleDepth: 0, 132 content: "", 133 expectedOutput: "\n---\n\n\n---\n", 134 }, 135 { 136 name: "empty content", 137 summary: "summary", 138 subTitleDepth: 1, 139 content: "", 140 expectedOutput: "\n---\n# summary\n\n---\n", 141 }, 142 { 143 name: "empty summary", 144 summary: "", 145 subTitleDepth: 1, 146 content: "content", 147 expectedOutput: "\n---\n# \n\n---\ncontent", 148 }, 149 { 150 name: "Main details", 151 summary: "summary", 152 subTitleDepth: 1, 153 content: "content", 154 expectedOutput: "\n---\n# summary\n\n---\ncontent", 155 }, 156 { 157 name: "Sub details", 158 summary: "summary", 159 subTitleDepth: 2, 160 content: "content", 161 expectedOutput: "\n---\n## summary\n\n---\ncontent", 162 }, 163 { 164 name: "Sub sub details", 165 summary: "summary", 166 subTitleDepth: 3, 167 content: "content", 168 expectedOutput: "\n---\n### summary\n\n---\ncontent", 169 }, 170 } 171 for _, tc := range testCases { 172 t.Run(tc.name, func(t *testing.T) { 173 smo := &SimplifiedOutput{} 174 assert.Equal(t, tc.expectedOutput, smo.MarkAsDetails(tc.summary, tc.subTitleDepth, tc.content)) 175 }) 176 } 177 } 178 179 func TestSimpleMarkAsTitle(t *testing.T) { 180 testCases := []struct { 181 name string 182 title string 183 expectedOutput string 184 subTitleDepth int 185 }{ 186 { 187 name: "empty", 188 title: "", 189 subTitleDepth: 0, 190 expectedOutput: "\n---\n\n\n---", 191 }, 192 { 193 name: "Main title", 194 title: "title", 195 subTitleDepth: 1, 196 expectedOutput: "\n---\n# title\n\n---", 197 }, 198 { 199 name: "Sub title", 200 title: "title", 201 subTitleDepth: 2, 202 expectedOutput: "\n---\n## title\n\n---", 203 }, 204 { 205 name: "Sub sub title", 206 title: "title", 207 subTitleDepth: 3, 208 expectedOutput: "\n---\n### title\n\n---", 209 }, 210 } 211 for _, tc := range testCases { 212 t.Run(tc.name, func(t *testing.T) { 213 smo := &SimplifiedOutput{} 214 assert.Equal(t, tc.expectedOutput, smo.MarkAsTitle(tc.title, tc.subTitleDepth)) 215 }) 216 } 217 }