Best Go-testdeep code snippet using test.Skipped
report_data_test.go
Source:report_data_test.go
...11 When("sorting test data", func() {12 tests := []string{"t1", "t2", "t3"}13 It("returns all tests", func() {14 data := map[string]map[string]*Details{15 "t3": {"a": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}}},16 }17 Expect(SortTestsByRelevance(data, tests)).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))18 })19 It("returns no duplicated tests", func() {20 data := map[string]map[string]*Details{21 "t1": {22 "a": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: MostlyFlaky, Jobs: []*Job{}},23 "b": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: Unimportant, Jobs: []*Job{}},24 },25 "t2": {"a": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: MildlyFlaky, Jobs: []*Job{}}},26 "t3": {"a": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}}},27 }28 Expect(SortTestsByRelevance(data, tests)).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))29 })30 It("returns no duplicated tests for the end", func() {31 data := map[string]map[string]*Details{32 "t1": {33 "a": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: MostlyFlaky, Jobs: []*Job{}},34 "b": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: Unimportant, Jobs: []*Job{}},35 },36 "t2": {37 "a": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: MildlyFlaky, Jobs: []*Job{}},38 "b": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: Unimportant, Jobs: []*Job{}},39 },40 "t3": {"a": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}}},41 }42 Expect(SortTestsByRelevance(data, tests)).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))43 })44 It("returns tests sorted descending by severity", func() {45 data := map[string]map[string]*Details{46 "t1": {"a": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: MostlyFlaky, Jobs: []*Job{}}},47 "t2": {"a": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: MildlyFlaky, Jobs: []*Job{}}},48 "t3": {"a": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}}},49 }50 Expect(SortTestsByRelevance(data, tests)).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))51 })52 It("returns tests of same severity sorted descending by number of severity points", func() {53 data := map[string]map[string]*Details{54 "t1": {55 "a": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}},56 "b": &Details{Failed: 3, Succeeded: 1, Skipped: 2, Severity: MostlyFlaky, Jobs: []*Job{}},57 },58 "t2": {59 "a": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}},60 "b": &Details{Failed: 2, Succeeded: 1, Skipped: 2, Severity: MildlyFlaky, Jobs: []*Job{}},61 },62 "t3": {63 "a": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}},64 "b": &Details{Failed: 4, Succeeded: 1, Skipped: 2, Severity: HeavilyFlaky, Jobs: []*Job{}},65 },66 }67 Expect(SortTestsByRelevance(data, tests)).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))68 })69 type testData struct {70 testName string71 failed []int72 succeeded []int73 skipped []int74 severity string75 }76 DescribeTable("returns tests of same severity weighted by total number of tests", func(expectations []testData, expectedTestNameOrder []string) {77 testData := map[string]map[string]*Details{}78 for _, expectation := range expectations {79 testData[expectation.testName] = map[string]*Details{}80 for index, failed := range expectation.failed {81 testData[expectation.testName][fmt.Sprint(index)] = &Details{Failed: failed, Succeeded: expectation.succeeded[index], Skipped: expectation.skipped[index], Severity: expectation.severity, Jobs: []*Job{}}82 }83 }84 Expect(SortTestsByRelevance(testData, tests)).To(BeEquivalentTo(expectedTestNameOrder))85 },86 Entry("zeros shouldn't be a problem",87 []testData{88 {testName: "t1", failed: []int{2}, succeeded: []int{0}, skipped: []int{2}, severity: HeavilyFlaky},89 {testName: "t2", failed: []int{1}, succeeded: []int{0}, skipped: []int{2}, severity: HeavilyFlaky},90 {testName: "t3", failed: []int{3}, succeeded: []int{0}, skipped: []int{2}, severity: HeavilyFlaky},91 },92 []string{"t3", "t1", "t2"},93 ),94 Entry("the more failures the higher",95 []testData{96 {testName: "t1", failed: []int{2}, succeeded: []int{1}, skipped: []int{2}, severity: HeavilyFlaky},97 {testName: "t2", failed: []int{1}, succeeded: []int{1}, skipped: []int{2}, severity: HeavilyFlaky},98 {testName: "t3", failed: []int{3}, succeeded: []int{1}, skipped: []int{2}, severity: HeavilyFlaky},99 },100 []string{"t3", "t1", "t2"},101 ),102 Entry("multiple values with zeros",103 []testData{104 {testName: "t1", failed: []int{2, 0}, succeeded: []int{1, 0}, skipped: []int{2, 2}, severity: HeavilyFlaky},105 {testName: "t2", failed: []int{1, 0}, succeeded: []int{1, 0}, skipped: []int{2, 2}, severity: HeavilyFlaky},106 {testName: "t3", failed: []int{3, 0}, succeeded: []int{1, 0}, skipped: []int{2, 2}, severity: HeavilyFlaky},107 },108 []string{"t3", "t1", "t2"},109 ),110 Entry("multiple values",111 []testData{112 {testName: "t1", failed: []int{4, 5}, succeeded: []int{1, 1}, skipped: []int{2, 2}, severity: HeavilyFlaky},113 {testName: "t2", failed: []int{3, 4}, succeeded: []int{1, 1}, skipped: []int{2, 2}, severity: HeavilyFlaky},114 {testName: "t3", failed: []int{6, 7}, succeeded: []int{1, 1}, skipped: []int{2, 2}, severity: HeavilyFlaky},115 },116 []string{"t3", "t1", "t2"},117 ),118 Entry("errors high, ratios small",119 []testData{120 {testName: "t1", failed: []int{6, 7}, succeeded: []int{5, 6}, skipped: []int{2, 2}, severity: HeavilyFlaky},121 {testName: "t2", failed: []int{4, 5}, succeeded: []int{3, 4}, skipped: []int{2, 2}, severity: HeavilyFlaky},122 {testName: "t3", failed: []int{11, 12}, succeeded: []int{10, 11}, skipped: []int{2, 2}, severity: HeavilyFlaky},123 },124 []string{"t3", "t1", "t2"},125 ),126 Entry("higher ratio, the higher",127 []testData{128 {testName: "t1", failed: []int{6, 7}, succeeded: []int{3, 4}, skipped: []int{2, 2}, severity: HeavilyFlaky},129 {testName: "t2", failed: []int{4, 5}, succeeded: []int{2, 3}, skipped: []int{2, 2}, severity: HeavilyFlaky},130 {testName: "t3", failed: []int{11, 12}, succeeded: []int{2, 1}, skipped: []int{2, 2}, severity: HeavilyFlaky},131 },132 []string{"t3", "t1", "t2"},133 ),134 Entry("mixed lengths",135 []testData{136 {testName: "t1", failed: []int{8, 10}, succeeded: []int{2, 1}, skipped: []int{2, 2}, severity: HeavilyFlaky},137 {testName: "t2", failed: []int{3, 4, 5}, succeeded: []int{1, 2, 3}, skipped: []int{2, 2, 2}, severity: HeavilyFlaky},138 {testName: "t3", failed: []int{22}, succeeded: []int{2}, skipped: []int{2}, severity: HeavilyFlaky},139 },140 []string{"t3", "t1", "t2"},141 ),142 // while the ratio here is higher for t2, we still want to emphazise the cases with higher failures more143 Entry("real life case 1: 10/9/2 > 9/9/3 > 6/3/12",144 []testData{145 {testName: "t1", failed: []int{9}, succeeded: []int{9}, skipped: []int{3}, severity: HeavilyFlaky},146 {testName: "t2", failed: []int{6}, succeeded: []int{3}, skipped: []int{12}, severity: HeavilyFlaky},147 {testName: "t3", failed: []int{10}, succeeded: []int{9}, skipped: []int{2}, severity: HeavilyFlaky},148 },149 []string{"t3", "t1", "t2"},150 ),151 Entry("real life case 2: 6/3/12 > 5/0/2 > 4/1/2",152 []testData{153 {testName: "t1", failed: []int{5}, succeeded: []int{0}, skipped: []int{2}, severity: HeavilyFlaky},154 {testName: "t2", failed: []int{4}, succeeded: []int{1}, skipped: []int{2}, severity: HeavilyFlaky},155 {testName: "t3", failed: []int{6}, succeeded: []int{3}, skipped: []int{12}, severity: HeavilyFlaky},156 },157 []string{"t3", "t1", "t2"},158 ),159 Entry("real life case 1: 15/1/0 > 13/0/3 > 3/0/13 > ",160 []testData{161 {testName: "t1", failed: []int{13}, succeeded: []int{0}, skipped: []int{3}, severity: HeavilyFlaky},162 {testName: "t2", failed: []int{3}, succeeded: []int{0}, skipped: []int{13}, severity: HeavilyFlaky},163 {testName: "t3", failed: []int{15}, succeeded: []int{1}, skipped: []int{0}, severity: HeavilyFlaky},164 },165 []string{"t3", "t1", "t2"},166 ),167 Entry("less number of succeeded, more severe: 5/1/13 > 5/3/3 > 5/5/0",168 []testData{169 {testName: "t1", failed: []int{5}, succeeded: []int{3}, skipped: []int{3}, severity: HeavilyFlaky},170 {testName: "t2", failed: []int{5}, succeeded: []int{5}, skipped: []int{13}, severity: HeavilyFlaky},171 {testName: "t3", failed: []int{5}, succeeded: []int{1}, skipped: []int{0}, severity: HeavilyFlaky},172 },173 []string{"t3", "t1", "t2"},174 ),175 )176 })177 When("sorting test via severity", func() {178 It("returns tests of same severity sorted descending by number of severity points", func() {179 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{180 "t1": {HeavilyFlaky: 2},181 "t2": {HeavilyFlaky: 1},182 "t3": {HeavilyFlaky: 3},183 })).To(BeEquivalentTo([]string{"t3", "t1", "t2"}))184 })185 It("returns tests of same severity and same number of severity points sorted lexically", func() {186 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{187 "tb": {HeavilyFlaky: 2},188 "tc": {HeavilyFlaky: 2},189 "ta": {HeavilyFlaky: 2},190 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))191 })192 It("returns tests of same severity sorted by lower severity", func() {193 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{194 "tb": {HeavilyFlaky: 2, MostlyFlaky: 2},195 "tc": {HeavilyFlaky: 2, MostlyFlaky: 1},196 "ta": {HeavilyFlaky: 2, MostlyFlaky: 3},197 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))198 })199 It("returns tests of same severity sorted by lower severity if even lower values present but zero", func() {200 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{201 "tb": {HeavilyFlaky: 2, MostlyFlaky: 2, ModeratelyFlaky: 0, MildlyFlaky: 0},202 "tc": {HeavilyFlaky: 2, MostlyFlaky: 1, ModeratelyFlaky: 0, MildlyFlaky: 0},203 "ta": {HeavilyFlaky: 2, MostlyFlaky: 3, ModeratelyFlaky: 0, MildlyFlaky: 0},204 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))205 })206 It("returns tests of same severity sorted by lower severity if inbetween values present but zero", func() {207 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{208 "tb": {HeavilyFlaky: 2, MostlyFlaky: 0, ModeratelyFlaky: 2, MildlyFlaky: 0},209 "tc": {HeavilyFlaky: 2, MostlyFlaky: 0, ModeratelyFlaky: 1, MildlyFlaky: 0},210 "ta": {HeavilyFlaky: 2, MostlyFlaky: 0, ModeratelyFlaky: 3, MildlyFlaky: 0},211 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))212 })213 It("returns tests of same severity sorted by lower severity if some inbetween values zero", func() {214 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{215 "tb": {HeavilyFlaky: 2, MostlyFlaky: 0, ModeratelyFlaky: 2, MildlyFlaky: 0},216 "tc": {HeavilyFlaky: 2, MostlyFlaky: 0, ModeratelyFlaky: 0, MildlyFlaky: 0},217 "ta": {HeavilyFlaky: 2, MostlyFlaky: 3, ModeratelyFlaky: 0, MildlyFlaky: 0},218 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))219 })220 It("returns tests of same severity sorted by lower severity if some inbetween values zero with more values", func() {221 Expect(BuildUpSortedTestsBySeverity(map[string]map[string]int{222 "tb": {HeavilyFlaky: 1, MostlyFlaky: 0, ModeratelyFlaky: 0, MildlyFlaky: 1, Fine: 0, Unimportant: 0},223 "tc": {HeavilyFlaky: 1, MostlyFlaky: 0, ModeratelyFlaky: 0, MildlyFlaky: 0, Fine: 0, Unimportant: 0},224 "ta": {HeavilyFlaky: 1, MostlyFlaky: 0, ModeratelyFlaky: 0, MildlyFlaky: 2, Fine: 0, Unimportant: 0},225 })).To(BeEquivalentTo([]string{"ta", "tb", "tc"}))226 })227 })228 DescribeTable("When comparing severity",229 func(a, b *TestToSeverityOccurrences, expected bool) {230 bySeverity := []*TestToSeverityOccurrences{a, b}231 Expect(BySeverity.Less(bySeverity, 0, 1)).To(BeEquivalentTo(expected))232 },233 Entry("ta -> Sev(2) less than tb -> Sev(2) is false",234 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},235 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{2}},236 false,237 ),238 Entry("tb -> Sev(2) less than ta -> Sev(2) is true",239 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{2}},240 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},241 true,242 ),243 Entry("ta -> Sev(2) less than ta -> Sev(2) is false",244 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},245 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},246 false,247 ),248 Entry("tb -> Sev(3) is less than ta -> Sev(2) is false",249 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3}},250 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},251 false,252 ),253 Entry("ta -> Sev(2) is less than tb -> Sev(3) is true",254 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{2}},255 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3}},256 true,257 ),258 Entry("tb -> Sev(3, 2) is less ta -> Sev(3, 3) is true",259 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3, 2}},260 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{3, 3}},261 true,262 ),263 Entry("tb -> Sev(3, 3) is less ta -> Sev(3, 2) is false",264 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3, 3}},265 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{3, 2}},266 false,267 ),268 Entry("tb -> Sev(3, 0, 3) is less ta -> Sev(3, 0, 2) is false",269 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3, 0, 3}},270 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{3, 0, 2}},271 false,272 ),273 Entry("tb -> Sev(3, 0, 2) is not less ta -> Sev(3, 0, 3) is true",274 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{3, 0, 2}},275 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{3, 0, 3}},276 true,277 ),278 Entry("tb -> Sev(1,0,0,2,0,0) is less ta -> Sev(1,0,0,1,0,0) is false",279 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{1, 0, 0, 2, 0, 0}},280 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{1, 0, 0, 1, 0, 0}},281 false,282 ),283 Entry("ta -> Sev(1,0,0,1,0,0) is less tb -> Sev(1,0,0,2,0,0) is true",284 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{1, 0, 0, 1, 0, 0}},285 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{1, 0, 0, 2, 0, 0}},286 true,287 ),288 Entry("tb -> Sev(1,0,1,0,0,0) is less ta -> Sev(1,0,0,1,0,0) is false",289 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{1, 0, 1, 0, 0, 0}},290 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{1, 0, 0, 1, 0, 0}},291 false,292 ),293 Entry("ta -> Sev(1,0,0,1,0,0) is less tb -> Sev(1,0,1,0,0,0) is true",294 &TestToSeverityOccurrences{Name: "ta", SeverityOccurrences: []int{1, 0, 0, 1, 0, 0}},295 &TestToSeverityOccurrences{Name: "tb", SeverityOccurrences: []int{1, 0, 1, 0, 0, 0}},296 true,297 ),298 )299 When("swapping elements", func() {300 It("Works", func() {301 bySeverity := []*TestToSeverityOccurrences{302 {Name: "tb", SeverityOccurrences: []int{3, 0, 2}},303 {Name: "ta", SeverityOccurrences: []int{3, 0, 3}},304 }305 BySeverity.Swap(bySeverity, 0, 1)306 Expect(bySeverity[0].Name).To(BeEquivalentTo("ta"))307 Expect(bySeverity[1].Name).To(BeEquivalentTo("tb"))308 })309 })310 DescribeTable("When calculating severity",311 func(details *Details, expected string) {312 SetSeverity(details)313 Expect(details.Severity).To(BeEquivalentTo(expected))314 },315 Entry("results having no failed tests but successful tests is fine", &Details{Failed: 0, Succeeded: 1, Skipped: 2, Jobs: []*Job{}}, Fine),316 Entry("results having no successful tests is heavily flaky", &Details{Failed: 1, Succeeded: 0, Skipped: 2, Jobs: []*Job{}}, HeavilyFlaky),317 Entry("results being HeavilyFlaky", &Details{Failed: 1, Succeeded: 1, Skipped: 2, Jobs: []*Job{}}, HeavilyFlaky),318 Entry("results being MostlyFlaky", &Details{Failed: 1, Succeeded: 2, Skipped: 2, Jobs: []*Job{}}, MostlyFlaky),319 Entry("results being ModeratelyFlaky", &Details{Failed: 1, Succeeded: 5, Skipped: 2, Jobs: []*Job{}}, ModeratelyFlaky),320 Entry("results being MildlyFlaky", &Details{Failed: 1, Succeeded: 10, Skipped: 2, Jobs: []*Job{}}, MildlyFlaky),321 )322 When("massaging test data", func() {323 const org = "org"324 const repo = "repo"325 const pr = 17326 const buildNumber = 1742327 var minusDay time.Duration328 BeforeEach(func() {329 duration, err := time.ParseDuration("24h")330 if err != nil {331 panic(err)332 }333 minusDay = -1 * duration334 })335 It("creates a result for PRs", func() {336 startOfReport := time.Now().Add(minusDay)337 endOfReport := time.Now()338 Expect(CreateFlakeReportData(339 []*JobResult{340 {341 Job: "job",342 JUnit: []junit.Suite{343 {344 Name: "suite",345 Package: "",346 Properties: nil,347 Tests: []junit.Test{348 {349 Name: "test1",350 Classname: "",351 Duration: 0,352 Status: junit.StatusPassed,353 Error: nil,354 Properties: nil,355 },356 {357 Name: "test2",358 Classname: "",359 Duration: 0,360 Status: junit.StatusSkipped,361 Error: nil,362 Properties: nil,363 },364 {365 Name: "test3",366 Classname: "",367 Duration: 0,368 Status: junit.StatusFailed,369 Error: nil,370 Properties: nil,371 },372 },373 SystemOut: "",374 SystemErr: "",375 Totals: junit.Totals{},376 },377 },378 BuildNumber: buildNumber,379 PR: pr,380 BatchPRs: nil,381 },382 },383 []int{pr},384 endOfReport,385 org,386 repo,387 startOfReport,388 )).To(BeEquivalentTo(389 Params{390 StartOfReport: startOfReport.Format(time.RFC3339),391 EndOfReport: endOfReport.Format(time.RFC3339),392 Headers: []string{"job"},393 Tests: []string{"test3"},394 Data: map[string]map[string]*Details{395 "test3": {396 "job": {397 Succeeded: 0,398 Skipped: 0,399 Failed: 1,400 Severity: "red",401 Jobs: []*Job{402 {BuildNumber: buildNumber, Severity: "red", PR: pr, BatchPRs: nil, Job: "job"},403 },404 },405 },406 },407 PrNumbers: []int{pr},408 Org: org,409 Repo: repo,410 FailuresForJobs: map[string]*JobFailures{411 fmt.Sprintf("job-%d", buildNumber): {BuildNumber: buildNumber, PR: pr, BatchPRs: nil, Job: "job", Failures: 1},412 },413 }))414 })415 It("creates a result for batch PRs", func() {416 startOfReport := time.Now().Add(minusDay)417 endOfReport := time.Now()418 Expect(CreateFlakeReportData(419 []*JobResult{420 {421 Job: "job",422 JUnit: []junit.Suite{423 {424 Name: "suite",425 Package: "",426 Properties: nil,427 Tests: []junit.Test{428 {429 Name: "test1",430 Classname: "",431 Duration: 0,432 Status: junit.StatusPassed,433 Error: nil,434 Properties: nil,435 },436 {437 Name: "test2",438 Classname: "",439 Duration: 0,440 Status: junit.StatusSkipped,441 Error: nil,442 Properties: nil,443 },444 {445 Name: "test3",446 Classname: "",447 Duration: 0,448 Status: junit.StatusFailed,449 Error: nil,450 Properties: nil,451 },452 },453 SystemOut: "",454 SystemErr: "",455 Totals: junit.Totals{},456 },457 },458 BuildNumber: buildNumber,459 PR: 0,460 BatchPRs: []int{pr},461 },462 },463 []int{pr},464 endOfReport,465 org,466 repo,467 startOfReport,468 )).To(BeEquivalentTo(469 Params{470 StartOfReport: startOfReport.Format(time.RFC3339),471 EndOfReport: endOfReport.Format(time.RFC3339),472 Headers: []string{"job"},473 Tests: []string{"test3"},474 Data: map[string]map[string]*Details{475 "test3": {476 "job": {477 Succeeded: 0,478 Skipped: 0,479 Failed: 1,480 Severity: "red",481 Jobs: []*Job{482 {BuildNumber: buildNumber, Severity: "red", PR: 0, BatchPRs: []int{pr}, Job: "job"},483 },484 },485 },486 },487 PrNumbers: []int{pr},488 Org: org,489 Repo: repo,490 FailuresForJobs: map[string]*JobFailures{491 fmt.Sprintf("job-%d", buildNumber): {BuildNumber: buildNumber, PR: 0, BatchPRs: []int{pr}, Job: "job", Failures: 1},492 },...
reporting_hooks_test.go
Source:reporting_hooks_test.go
...64 So(1, ShouldBeNil)65 })66 expectEqual(t, "Begin|A|Success|Failure|Exit|End", myReporter.wholeStory())67}68func TestIncompleteActionReportedAsSkipped(t *testing.T) {69 myReporter, test := setupFakeReporter()70 Convey("A", test, func() {71 Convey("B", nil)72 })73 expectEqual(t, "Begin|A|B|Skipped|Exit|Exit|End", myReporter.wholeStory())74}75func TestSkippedConveyReportedAsSkipped(t *testing.T) {76 myReporter, test := setupFakeReporter()77 Convey("A", test, func() {78 SkipConvey("B", func() {79 So(1, ShouldEqual, 1)80 })81 })82 expectEqual(t, "Begin|A|B|Skipped|Exit|Exit|End", myReporter.wholeStory())83}84func TestMultipleSkipsAreReported(t *testing.T) {85 myReporter, test := setupFakeReporter()86 Convey("A", test, func() {87 Convey("0", func() {88 So(nil, ShouldBeNil)89 })90 SkipConvey("1", func() {})91 SkipConvey("2", func() {})92 Convey("3", nil)93 Convey("4", nil)94 Convey("5", func() {95 So(nil, ShouldBeNil)96 })97 })98 expected := "Begin" +99 "|A|0|Success|Exit|Exit" +100 "|A|1|Skipped|Exit|Exit" +101 "|A|2|Skipped|Exit|Exit" +102 "|A|3|Skipped|Exit|Exit" +103 "|A|4|Skipped|Exit|Exit" +104 "|A|5|Success|Exit|Exit" +105 "|End"106 expectEqual(t, expected, myReporter.wholeStory())107}108func TestSkippedAssertionIsNotReported(t *testing.T) {109 myReporter, test := setupFakeReporter()110 Convey("A", test, func() {111 SkipSo(1, ShouldEqual, 1)112 })113 expectEqual(t, "Begin|A|Skipped|Exit|End", myReporter.wholeStory())114}115func TestMultipleSkippedAssertionsAreNotReported(t *testing.T) {116 myReporter, test := setupFakeReporter()117 Convey("A", test, func() {118 SkipSo(1, ShouldEqual, 1)119 So(1, ShouldEqual, 1)120 SkipSo(1, ShouldEqual, 1)121 })122 expectEqual(t, "Begin|A|Skipped|Success|Skipped|Exit|End", myReporter.wholeStory())123}124func TestErrorByManualPanicReported(t *testing.T) {125 myReporter, test := setupFakeReporter()126 Convey("A", test, func() {127 panic("Gopher alert!")128 })129 expectEqual(t, "Begin|A|Error|Exit|End", myReporter.wholeStory())130}131func TestIterativeConveysReported(t *testing.T) {132 myReporter, test := setupFakeReporter()133 Convey("A", test, func() {134 for x := 0; x < 3; x++ {135 Convey(strconv.Itoa(x), func() {136 So(x, ShouldEqual, x)137 })138 }139 })140 expectEqual(t, "Begin|A|0|Success|Exit|Exit|A|1|Success|Exit|Exit|A|2|Success|Exit|Exit|End", myReporter.wholeStory())141}142func TestNestedIterativeConveysReported(t *testing.T) {143 myReporter, test := setupFakeReporter()144 Convey("A", test, func() {145 for x := 0; x < 3; x++ {146 Convey(strconv.Itoa(x), func() {147 for y := 0; y < 3; y++ {148 Convey("< "+strconv.Itoa(y), func() {149 So(x, ShouldBeLessThan, y)150 })151 }152 })153 }154 })155 expectEqual(t, ("Begin|" +156 "A|0|< 0|Failure|Exit|Exit|Exit|" +157 "A|0|< 1|Success|Exit|Exit|Exit|" +158 "A|0|< 2|Success|Exit|Exit|Exit|" +159 "A|1|< 0|Failure|Exit|Exit|Exit|" +160 "A|1|< 1|Failure|Exit|Exit|Exit|" +161 "A|1|< 2|Success|Exit|Exit|Exit|" +162 "A|2|< 0|Failure|Exit|Exit|Exit|" +163 "A|2|< 1|Failure|Exit|Exit|Exit|" +164 "A|2|< 2|Failure|Exit|Exit|Exit|" +165 "End"), myReporter.wholeStory())166}167func TestEmbeddedAssertionReported(t *testing.T) {168 myReporter, test := setupFakeReporter()169 Convey("A", test, func(c C) {170 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {171 c.So(r.FormValue("msg"), ShouldEqual, "ping")172 }))173 http.DefaultClient.Get(ts.URL + "?msg=ping")174 })175 expectEqual(t, "Begin|A|Success|Exit|End", myReporter.wholeStory())176}177func TestEmbeddedContextHelperReported(t *testing.T) {178 myReporter, test := setupFakeReporter()179 helper := func(c C) http.HandlerFunc {180 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {181 c.Convey("Embedded", func() {182 So(r.FormValue("msg"), ShouldEqual, "ping")183 })184 })185 }186 Convey("A", test, func(c C) {187 ts := httptest.NewServer(helper(c))188 http.DefaultClient.Get(ts.URL + "?msg=ping")189 })190 expectEqual(t, "Begin|A|Embedded|Success|Exit|Exit|End", myReporter.wholeStory())191}192func expectEqual(t *testing.T, expected interface{}, actual interface{}) {193 if expected != actual {194 _, file, line, _ := runtime.Caller(1)195 t.Errorf("Expected '%v' to be '%v' but it wasn't. See '%s' at line %d.",196 actual, expected, path.Base(file), line)197 }198}199func setupFakeReporter() (*fakeReporter, *fakeGoTest) {200 myReporter := new(fakeReporter)201 myReporter.calls = []string{}202 Cfg.testReporter = myReporter203 return myReporter, new(fakeGoTest)204}205type fakeReporter struct {206 calls []string207}208func (self *fakeReporter) BeginStory(story *reporting.StoryReport) {209 self.calls = append(self.calls, "Begin")210}211func (self *fakeReporter) Enter(scope *reporting.ScopeReport) {212 self.calls = append(self.calls, scope.Title)213}214func (self *fakeReporter) Report(report *reporting.AssertionResult) {215 if report.Error != nil {216 self.calls = append(self.calls, "Error")217 } else if report.Failure != "" {218 message := "Failure"219 if report.Expected != "" || report.Actual != "" {220 message += fmt.Sprintf("(%s/%s)", report.Expected, report.Actual)221 }222 self.calls = append(self.calls, message)223 } else if report.Skipped {224 self.calls = append(self.calls, "Skipped")225 } else {226 self.calls = append(self.calls, "Success")227 }228}229func (self *fakeReporter) Exit() {230 self.calls = append(self.calls, "Exit")231}232func (self *fakeReporter) EndStory() {233 self.calls = append(self.calls, "End")234}235func (self *fakeReporter) Write(content []byte) (int, error) {236 return len(content), nil // no-op237}238func (self *fakeReporter) wholeStory() string {...
main.go
Source:main.go
1// Copyright 2020 The Cockroach Authors.2//3// Use of this software is governed by the Business Source License4// included in the file licenses/BSL.txt.5//6// As of the Change Date specified in that file, in accordance with7// the Business Source License, use of this software will be governed8// by the Apache License, Version 2.0, included in the file9// licenses/APL.txt.10package main11import (12 "bytes"13 "flag"14 "fmt"15 "go/build"16 "log"17 "os/exec"18 "path/filepath"19 "regexp"20 "sort"21 "strings"22 "github.com/cockroachdb/errors"23 "github.com/ghemawat/stream"24 "github.com/nlopes/slack"25)26var slackToken = flag.String("slack-token", "", "Slack bot token")27var slackChannel = flag.String("slack-channel", "test-infra-ops", "Slack channel")28type skippedTest struct {29 file string30 test string31}32func dirCmd(dir string, name string, args ...string) stream.Filter {33 cmd := exec.Command(name, args...)34 cmd.Dir = dir35 out, err := cmd.CombinedOutput()36 switch {37 case err == nil:38 case errors.HasType(err, (*exec.ExitError)(nil)):39 // Non-zero exit is expected.40 default:41 log.Fatal(err)42 }43 return stream.ReadLines(bytes.NewReader(out))44}45func makeSlackClient() *slack.Client {46 if *slackToken == "" {47 return nil48 }49 return slack.New(*slackToken)50}51func findChannel(client *slack.Client, name string) (string, error) {52 if client != nil {53 channels, err := client.GetChannels(true)54 if err != nil {55 return "", err56 }57 for _, channel := range channels {58 if channel.Name == name {59 return channel.ID, nil60 }61 }62 }63 return "", fmt.Errorf("not found")64}65func postReport(skipped []skippedTest) {66 client := makeSlackClient()67 if client == nil {68 fmt.Printf("no slack client\n")69 return70 }71 channel, _ := findChannel(client, *slackChannel)72 if channel == "" {73 fmt.Printf("unable to find slack channel: %q\n", *slackChannel)74 return75 }76 params := slack.PostMessageParameters{77 Username: "Craig Cockroach",78 }79 status := "good"80 switch n := len(skipped); {81 case n >= 100:82 status = "danger"83 case n > 10:84 status = "warning"85 }86 message := fmt.Sprintf("%d skipped tests", len(skipped))87 fmt.Println(message)88 params.Attachments = append(params.Attachments,89 slack.Attachment{90 Color: status,91 Title: message,92 Fallback: message,93 })94 fileMap := make(map[string]int)95 for i := range skipped {96 fileMap[skipped[i].file]++97 }98 files := make([]string, 0, len(fileMap))99 for file := range fileMap {100 files = append(files, file)101 }102 sort.Strings(files)103 var buf bytes.Buffer104 for _, file := range files {105 fmt.Fprintf(&buf, "%3d %s\n", fileMap[file], file)106 }107 fmt.Print(buf.String())108 params.Attachments = append(params.Attachments,109 slack.Attachment{110 Color: status,111 Text: fmt.Sprintf("```\n%s```\n", buf.String()),112 })113 if _, _, err := client.PostMessage(channel, "", params); err != nil {114 fmt.Printf("unable to post slack report: %v\n", err)115 return116 }117 fmt.Printf("posted slack report\n")118}119func main() {120 flag.Parse()121 const root = "github.com/cockroachdb/cockroach"122 crdb, err := build.Import(root, "", build.FindOnly)123 if err != nil {124 log.Fatal(err)125 }126 pkgDir := filepath.Join(crdb.Dir, "pkg")127 // NB: This only matches tests, not benchmarks. We can change this to match128 // benchmarks if we want to report on skipped benchmarks too.129 testnameRE := regexp.MustCompile(`([^:]+):func (Test[^(]*).*`)130 // We grep for all test and benchmark names, along with calls to Skip and131 // Skipf. We then loop over this output keeping track of the most recent132 // test/benchmark seen so we can associate the Skip call with the correct133 // test.134 filter := stream.Sequence(135 dirCmd(pkgDir, "git", "grep", "-E", `^func (Test|Benchmark)|\.Skipf?\(`),136 // Short-list of skip reasons to exclude from reporting.137 //138 // TODO(peter): We should probably have an explicit exclude marker.139 stream.GrepNot(`short|PKG specified`),140 )141 var skipped []skippedTest142 var lastTest string143 if err := stream.ForEach(filter, func(s string) {144 switch {145 case strings.Contains(s, ":func "):146 lastTest = s147 case strings.Contains(s, ".Skip"):148 m := testnameRE.FindStringSubmatch(lastTest)149 if m != nil {150 file, test := m[1], m[2]151 skipped = append(skipped, skippedTest{152 file: file,153 test: test,154 })155 // Clear the test so we don't report it more than once.156 lastTest = ""157 }158 }159 }); err != nil {160 log.Fatal(err)161 }162 postReport(skipped)163}...
Skipped
Using AI Code Generation
1import (2func TestSkipped(t *testing.T) {3 t.Skip("This test is skipped")4}5import (6func TestFailed(t *testing.T) {7 t.Fail()8}9import (10func TestLog(t *testing.T) {11 t.Log("This is a log")12}13import (14func TestLogf(t *testing.T) {15 t.Logf("This is a %s", "log")16}17import (18func TestError(t *testing.T) {19 t.Error("This is an error")20}21import (22func TestErrorf(t *testing.T) {23 t.Errorf("This is an %s", "error")24}25import (26func TestFatal(t *testing.T) {27 t.Fatal("This is a fatal error")28}29import (30func TestFatalf(t *testing.T) {31 t.Fatalf("This is a %s", "fatal error")32}33import (34func TestParallel(t *testing.T) {35 t.Parallel()36}37import (38func TestRun(t *testing.T) {39 t.Run("Run", func(t *testing.T) {40 t.Log("This is a log")41 })42}43import (44func TestRun(t *testing.T) {45 t.Run("Run", func(t *testing.T) {
Skipped
Using AI Code Generation
1import (2func TestSkipped(t *testing.T) {3 t.Skip("skipping test in short mode")4}5func TestNotSkipped(t *testing.T) {6 fmt.Println("Not skipped")7}8func TestMain(m *testing.M) {9 fmt.Println("Testing")10 m.Run()11}12--- SKIP: TestSkipped (0.00s)13import (14func TestSkipNow(t *testing.T) {15 t.SkipNow()16}17func TestNotSkipped(t *testing.T) {18 fmt.Println("Not skipped")19}20func TestMain(m *testing.M) {21 fmt.Println("Testing")22 m.Run()23}24--- SKIP: TestSkipNow (0.00s)25import (26func TestSkipf(t *testing.T) {27 t.Skipf("Skipping this test")28}29func TestNotSkipped(t *testing.T) {30 fmt.Println("Not skipped")31}32func TestMain(m *testing.M) {33 fmt.Println("Testing")34 m.Run()35}36--- SKIP: TestSkipf (0.00s)
Skipped
Using AI Code Generation
1import "testing"2func TestSkip(t *testing.T) {3 t.Skip("skipping test in short mode")4}5import "testing"6func TestSkip(t *testing.T) {7 t.SkipNow()8}9import "testing"10func TestSkip(t *testing.T) {11 t.Skip("skipping test in short mode")12}13import "testing"14func TestSkip(t *testing.T) {15 t.Skip("skipping test in short mode")16}17import "testing"18func TestSkip(t *testing.T) {19 t.Skip("skipping test in short mode")20}21import "testing"22func TestSkip(t *testing.T) {23 t.Skip("skipping test in short mode")24}25import "testing"26func TestSkip(t *testing.T) {27 t.Skip("skipping test in short mode")28}29import "testing"30func TestSkip(t *testing.T) {31 t.Skip("skipping test in short mode")32}33import "testing"34func TestSkip(t *testing.T) {35 t.Skip("skipping test in short mode")36}37import "testing"38func TestSkip(t *testing.T) {39 t.Skip("skipping test in short mode")40}41import "testing"42func TestSkip(t *testing.T) {43 t.Skip("skipping test in short mode")44}
Skipped
Using AI Code Generation
1func TestSkip(t *testing.T) {2 if runtime.GOOS == "windows" {3 t.Skip("Can't run this test on windows")4 }5}6func TestSkip(t *testing.T) {7 if runtime.GOOS == "windows" {8 t.SkipNow()9 }10}11func TestSkip(t *testing.T) {12 if runtime.GOOS == "windows" {13 t.Skip("Can't run this test on windows")14 }15}16func TestSkip(t *testing.T) {17 if runtime.GOOS == "windows" {18 t.Skip("Can't run this test on windows")19 }20}21func TestSkip(t *testing.T) {22 if runtime.GOOS == "windows" {23 t.Skip("Can't run this test on windows")24 }25}26func TestSkip(t *testing.T) {27 if runtime.GOOS == "windows" {28 t.Skip("Can't run this test on windows")29 }30}31func TestSkip(t *testing.T) {32 if runtime.GOOS == "windows" {33 t.Skip("Can't run this test on windows")34 }35}36func TestSkip(t *testing.T) {37 if runtime.GOOS == "windows" {38 t.Skip("Can't run this test on windows")39 }40}41func TestSkip(t *testing.T) {42 if runtime.GOOS == "windows" {43 t.Skip("Can't run this test on windows")44 }45}46func TestSkip(t *testing.T) {
Skipped
Using AI Code Generation
1import (2func TestSkipped(t *testing.T) {3 t.Skip()4}5func TestPass(t *testing.T) {6 t.Skip("Skipping this test")7}8func TestFail(t *testing.T) {9 t.Fail()10}11func TestFailNow(t *testing.T) {12 t.FailNow()13}14func TestFatal(t *testing.T) {15 t.Fatal()16}17func TestLog(t *testing.T) {18 t.Log()19}20func TestParallel(t *testing.T) {21 t.Parallel()22}23func TestSkipNow(t *testing.T) {24 t.SkipNow()25}26func TestSkip(t *testing.T) {27 t.Skip()28}29func TestSkipf(t *testing.T) {30 t.Skipf("Skipping this test")31}32func TestHelper(t *testing.T) {33 t.Helper()34}35func TestCleanup(t *testing.T) {36 t.Cleanup()37}38func TestCleanupf(t *testing.T) {39 t.Cleanup(func() {})40}41func TestRun(t *testing.T) {42 t.Run("TestRun", func(t *testing.T) {43 t.Skip()44 })45}46func TestSkipNow(t *testing.T) {47 t.SkipNow()48}49func TestSkip(t *testing.T) {50 t.Skip()51}52func TestSkipf(t *testing.T) {53 t.Skipf("Skipping this test")54}55func TestHelper(t *testing.T) {56 t.Helper()57}58func TestCleanup(t *testing.T) {59 t.Cleanup()60}61func TestCleanupf(t *testing.T) {62 t.Cleanup(func() {})63}64func TestRun(t *testing.T) {65 t.Run("TestRun", func(t *testing.T) {66 t.Skip()67 })68}69func TestSkipNow(t *testing.T) {70 t.SkipNow()71}72func TestSkip(t *testing.T) {73 t.Skip()74}75func TestSkipf(t *testing.T) {76 t.Skipf("Skipping this test")77}78func TestHelper(t *testing.T) {79 t.Helper()80}81func TestCleanup(t *testing.T) {82 t.Cleanup()83}84func TestCleanupf(t *testing.T) {85 t.Cleanup(func() {})86}87func TestRun(t *testing.T) {88 t.Run("TestRun", func(t *testing.T) {89 t.Skip()90 })91}92func TestSkipNow(t *testing.T) {93 t.SkipNow()94}95func TestSkip(t *testing.T) {96 t.Skip()97}
Skipped
Using AI Code Generation
1import (2func TestSkipped(t *testing.T) {3 t.Skip("Skipping this test")4 t.Log("This will not be printed")5}6--- SKIP: TestSkipped (0.00s)73. FailNow() Method8import (9func TestFailNow(t *testing.T) {10 t.Log("Starting")11 t.FailNow()12 t.Log("This will not be printed")13}14--- FAIL: TestFailNow (0.00s)154. Log() Method16import (17func TestLog(t *testing.T) {18 t.Log("Starting")19 t.Log("This is a log")20 t.Log("Ending")21}22--- PASS: TestLog (0.00s)235. Logf() Method24import (25func TestLogf(t *testing.T) {26 t.Logf("Starting %v", "Test")27 t.Logf("This is a %s", "log")28 t.Logf("Ending %v", "Test")29}30--- PASS: TestLogf (0.00s)
Skipped
Using AI Code Generation
1import (2func TestSkip(t *testing.T) {3 if 1 == 1 {4 t.Skip("skipping")5 }6 t.Error("this should not be printed")7}8func TestSkipNow(t *testing.T) {9 if 1 == 1 {10 t.SkipNow()11 }12 t.Error("this should not be printed")13}14--- SKIP: TestSkip (0.00s)15--- SKIP: TestSkipNow (0.00s)16import (17func BenchmarkConcat(b *testing.B) {18 for i := 0; i < b.N; i++ {19 Concat("Hello", "World")20 }21}22func Concat(str1
Skipped
Using AI Code Generation
1import (2func TestSkipped(t *testing.T) {3 t.Skip("TestSkipped")4 fmt.Println("TestSkipped")5}6--- SKIP: TestSkipped (0.00s)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!