github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/logger/parser/parser_test.go (about) 1 package parser 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestGetIndent(t *testing.T) { 10 t.Parallel() 11 12 testCases := []struct { 13 name string 14 in string 15 out string 16 }{ 17 { 18 "BaseCase", 19 " --- FAIL: TestSnafu", 20 " ", 21 }, 22 { 23 "NoIndent", 24 "--- FAIL: TestSnafu", 25 "", 26 }, 27 { 28 "EmptyString", 29 "", 30 "", 31 }, 32 { 33 "Tabs", 34 "\t\t---FAIL: TestSnafu", 35 "\t\t", 36 }, 37 { 38 "MixTabSpace", 39 "\t ---FAIL: TestSnafu", 40 "\t ", 41 }, 42 } 43 44 for _, testCase := range testCases { 45 testCase := testCase 46 t.Run(testCase.name, func(t *testing.T) { 47 assert.Equal( 48 t, 49 getIndent(testCase.in), 50 testCase.out, 51 ) 52 }) 53 } 54 } 55 56 func TestGetTestNameFromResultLine(t *testing.T) { 57 t.Parallel() 58 59 testCases := []struct { 60 name string 61 in string 62 out string 63 }{ 64 { 65 "BaseCase", 66 "--- PASS: TestGetTestNameFromResultLine (0.00s)", 67 "TestGetTestNameFromResultLine", 68 }, 69 { 70 "Indented", 71 " --- PASS: TestGetTestNameFromResultLine/Indented (0.00s)", 72 "TestGetTestNameFromResultLine/Indented", 73 }, 74 { 75 "SpecialChars", 76 " --- PASS: TestGetTestNameFromResultLine/SpecialChars---_FAIL (0.00s)", 77 "TestGetTestNameFromResultLine/SpecialChars---_FAIL", 78 }, 79 { 80 "WhenFailed", 81 "--- FAIL: TestGetTestNameFromResultLine (0.00s)", 82 "TestGetTestNameFromResultLine", 83 }, 84 } 85 86 for _, testCase := range testCases { 87 testCase := testCase 88 t.Run(testCase.name, func(t *testing.T) { 89 assert.Equal( 90 t, 91 getTestNameFromResultLine(testCase.in), 92 testCase.out, 93 ) 94 }) 95 } 96 } 97 98 func TestIsResultLine(t *testing.T) { 99 t.Parallel() 100 101 testCases := []struct { 102 name string 103 in string 104 out bool 105 }{ 106 { 107 "BaseCase", 108 "--- PASS: TestIsResultLine (0.00s)", 109 true, 110 }, 111 { 112 "Indented", 113 " --- PASS: TestIsResultLine/Indented (0.00s)", 114 true, 115 }, 116 { 117 "SpecialChars", 118 " --- PASS: TestIsResultLine/SpecialChars---_FAIL (0.00s)", 119 true, 120 }, 121 { 122 "WhenFailed", 123 "--- FAIL: TestIsResultLine (0.00s)", 124 true, 125 }, 126 { 127 "NonResultLine", 128 "=== RUN TestIsResultLine", 129 false, 130 }, 131 } 132 133 for _, testCase := range testCases { 134 testCase := testCase 135 t.Run(testCase.name, func(t *testing.T) { 136 assert.Equal( 137 t, 138 isResultLine(testCase.in), 139 testCase.out, 140 ) 141 }) 142 } 143 } 144 145 func TestGetTestNameFromStatusLine(t *testing.T) { 146 t.Parallel() 147 148 testCases := []struct { 149 name string 150 in string 151 out string 152 }{ 153 { 154 "BaseCase", 155 "=== RUN TestGetTestNameFromStatusLine", 156 "TestGetTestNameFromStatusLine", 157 }, 158 { 159 "Indented", 160 " === RUN TestGetTestNameFromStatusLine/Indented", 161 "TestGetTestNameFromStatusLine/Indented", 162 }, 163 { 164 "SpecialChars", 165 "=== RUN TestGetTestNameFromStatusLine/SpecialChars---_FAIL", 166 "TestGetTestNameFromStatusLine/SpecialChars---_FAIL", 167 }, 168 { 169 "WhenPaused", 170 "=== PAUSE TestGetTestNameFromStatusLine", 171 "TestGetTestNameFromStatusLine", 172 }, 173 { 174 "WhenCont", 175 "=== CONT TestGetTestNameFromStatusLine", 176 "TestGetTestNameFromStatusLine", 177 }, 178 } 179 180 for _, testCase := range testCases { 181 testCase := testCase 182 t.Run(testCase.name, func(t *testing.T) { 183 assert.Equal( 184 t, 185 getTestNameFromStatusLine(testCase.in), 186 testCase.out, 187 ) 188 }) 189 } 190 } 191 192 func TestIsStatusLine(t *testing.T) { 193 t.Parallel() 194 195 testCases := []struct { 196 name string 197 in string 198 out bool 199 }{ 200 { 201 "BaseCase", 202 "=== RUN TestGetTestNameFromStatusLine", 203 true, 204 }, 205 { 206 "Indented", 207 " === RUN TestGetTestNameFromStatusLine/Indented", 208 true, 209 }, 210 { 211 "SpecialChars", 212 "=== RUN TestGetTestNameFromStatusLine/SpecialChars---_FAIL", 213 true, 214 }, 215 { 216 "WhenPaused", 217 "=== PAUSE TestGetTestNameFromStatusLine", 218 true, 219 }, 220 { 221 "WhenCont", 222 "=== CONT TestGetTestNameFromStatusLine", 223 true, 224 }, 225 { 226 "NonStatusLine", 227 "--- FAIL: TestIsStatusLine", 228 false, 229 }, 230 } 231 232 for _, testCase := range testCases { 233 testCase := testCase 234 t.Run(testCase.name, func(t *testing.T) { 235 assert.Equal( 236 t, 237 isStatusLine(testCase.in), 238 testCase.out, 239 ) 240 }) 241 } 242 } 243 244 func TestIsSummaryLine(t *testing.T) { 245 t.Parallel() 246 247 testCases := []struct { 248 name string 249 in string 250 out bool 251 }{ 252 { 253 "BaseCase", 254 "ok github.com/gruntwork-io/terratest/test 812.034s", 255 true, 256 }, 257 { 258 "NotSummary", 259 "--- FAIL: TestIsStatusLine", 260 false, 261 }, 262 } 263 264 for _, testCase := range testCases { 265 testCase := testCase 266 t.Run(testCase.name, func(t *testing.T) { 267 assert.Equal( 268 t, 269 isSummaryLine(testCase.in), 270 testCase.out, 271 ) 272 }) 273 } 274 } 275 276 func TestIsPanicLine(t *testing.T) { 277 t.Parallel() 278 279 testCases := []struct { 280 name string 281 in string 282 out bool 283 }{ 284 { 285 "BaseCase", 286 "panic: error [recovered]", 287 true, 288 }, 289 { 290 "NotPanic", 291 "--- FAIL: TestIsStatusLine", 292 false, 293 }, 294 } 295 296 for _, testCase := range testCases { 297 testCase := testCase 298 t.Run(testCase.name, func(t *testing.T) { 299 assert.Equal( 300 t, 301 isPanicLine(testCase.in), 302 testCase.out, 303 ) 304 }) 305 } 306 }