Best Testkube code snippet using testresult.Statuses
task_history_test.go
Source:task_history_test.go
...149 Convey("a test history parameters struct without a task status should have a default set", func() {150 params := TestHistoryParameters{151 Project: "project",152 TestNames: []string{"test"},153 TestStatuses: []string{evergreen.TestFailedStatus, evergreen.TestSucceededStatus},154 Limit: 10,155 }156 So(len(params.TaskStatuses), ShouldEqual, 0)157 So(params.SetDefaultsAndValidate(), ShouldBeNil)158 So(len(params.TaskStatuses), ShouldEqual, 1)159 So(params.TaskStatuses[0], ShouldEqual, evergreen.TaskFailed)160 })161 Convey("a test history parameters struct without a test status should have a default set", func() {162 params := TestHistoryParameters{163 Project: "project",164 TestNames: []string{"test"},165 TaskStatuses: []string{evergreen.TaskFailed},166 Limit: 10,167 }168 So(len(params.TestStatuses), ShouldEqual, 0)169 So(params.SetDefaultsAndValidate(), ShouldBeNil)170 So(len(params.TestStatuses), ShouldEqual, 1)171 So(params.TestStatuses[0], ShouldEqual, evergreen.TestFailedStatus)172 })173 Convey("a test history parameters struct with an invalid test status should not be valid", func() {174 params := TestHistoryParameters{175 Project: "project",176 TestNames: []string{"test"},177 TestStatuses: []string{"blah"},178 }179 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)180 })181 Convey("a test history parameters struct with an invalid task status should not be valid", func() {182 params := TestHistoryParameters{183 Project: "project",184 TestNames: []string{"test"},185 TaskStatuses: []string{"blah"},186 }187 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)188 })189 Convey("a test history parameters struct with both a date and revision should not be valid", func() {190 params := TestHistoryParameters{191 Project: "project",192 TestNames: []string{"test"},193 AfterRevision: "abc",194 BeforeDate: time.Now(),195 }196 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)197 params = TestHistoryParameters{198 Project: "project",199 TestNames: []string{"test"},200 BeforeRevision: "abc",201 BeforeDate: time.Now(),202 }203 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)204 params = TestHistoryParameters{205 Project: "project",206 TestNames: []string{"test"},207 AfterRevision: "abc",208 AfterDate: time.Now(),209 }210 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)211 params = TestHistoryParameters{212 Project: "project",213 TestNames: []string{"test"},214 BeforeRevision: "abc",215 AfterDate: time.Now(),216 }217 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)218 params = TestHistoryParameters{219 Project: "project",220 TestNames: []string{"test"},221 AfterRevision: "abc",222 BeforeDate: time.Now(),223 BeforeRevision: "abc",224 AfterDate: time.Now(),225 }226 So(params.SetDefaultsAndValidate(), ShouldNotBeNil)227 })228 })229}230func TestBuildTestHistoryQuery(t *testing.T) {231 Convey("With a version", t, func() {232 require.NoError(t, db.ClearCollections(task.Collection, VersionCollection))233 testVersion := Version{234 Id: "testVersion",235 Revision: "abc",236 RevisionOrderNumber: 1,237 Identifier: "project",238 Requester: evergreen.RepotrackerVersionRequester,239 }240 So(testVersion.Insert(), ShouldBeNil)241 Convey("with setting the defaults of the test history parameters and having task names in the parameters", func() {242 params := TestHistoryParameters{243 Project: "project",244 TaskNames: []string{"task1", "task2"},245 Limit: 20,246 }247 So(params.SetDefaultsAndValidate(), ShouldBeNil)248 Convey("the pipeline created should be properly created with relevant fields", func() {249 pipeline, err := buildTestHistoryQuery(¶ms)250 So(err, ShouldBeNil)251 So(len(pipeline), ShouldEqual, 8)252 Convey("the $match task query should have task names included", func() {253 So(pipeline[0], ShouldContainKey, "$match")254 taskMatchQuery := bson.M{255 "$or": []bson.M{256 bson.M{257 task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},258 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{259 "$ne": true,260 },261 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{262 "$ne": evergreen.CommandTypeSystem,263 }}},264 task.ProjectKey: "project",265 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},266 }267 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)268 })269 })270 Convey("with setting the test names, the task names and adding a build variant", func() {271 params.TestNames = []string{"test1"}272 params.TaskNames = []string{"task1", "task2"}273 params.BuildVariants = []string{"osx"}274 Convey("with adding in a before revision and validating", func() {275 params.BeforeRevision = "abc"276 So(params.SetDefaultsAndValidate(), ShouldBeNil)277 Convey("the pipeline should be created properly", func() {278 pipeline, err := buildTestHistoryQuery(¶ms)279 So(err, ShouldBeNil)280 So(len(pipeline), ShouldEqual, 8)281 Convey("the $match task query should have the test names included", func() {282 So(pipeline[0], ShouldContainKey, "$match")283 taskMatchQuery := bson.M{284 "$or": []bson.M{285 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},286 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{287 "$ne": true,288 },289 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{290 "$ne": evergreen.CommandTypeSystem,291 }}},292 task.ProjectKey: "project",293 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},294 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},295 task.RevisionOrderNumberKey: bson.M{"$lte": 1},296 }297 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)298 })299 Convey("the $match test query should have the test names included", func() {300 So(pipeline[4], ShouldContainKey, "$match")301 testMatchQuery := bson.M{302 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},303 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},304 }305 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)306 })307 })308 })309 Convey("with adding in an after revision and validating", func() {310 params.AfterRevision = "abc"311 So(params.SetDefaultsAndValidate(), ShouldBeNil)312 Convey("the pipeline should be created properly", func() {313 pipeline, err := buildTestHistoryQuery(¶ms)314 So(err, ShouldBeNil)315 So(len(pipeline), ShouldEqual, 8)316 Convey("the $match task query should have the test names included", func() {317 So(pipeline[0], ShouldContainKey, "$match")318 taskMatchQuery := bson.M{319 "$or": []bson.M{320 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},321 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{322 "$ne": true,323 },324 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{325 "$ne": evergreen.CommandTypeSystem,326 }}},327 task.ProjectKey: "project",328 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},329 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},330 task.RevisionOrderNumberKey: bson.M{"$gt": 1},331 }332 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)333 })334 Convey("the $match test query should have the test names included", func() {335 So(pipeline[4], ShouldContainKey, "$match")336 testMatchQuery := bson.M{337 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},338 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},339 }340 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)341 })342 })343 })344 Convey("with adding in a before and after revision and validating", func() {345 params.AfterRevision = "abc"346 params.BeforeRevision = "abc"347 So(params.SetDefaultsAndValidate(), ShouldBeNil)348 Convey("the pipeline should be created properly", func() {349 pipeline, err := buildTestHistoryQuery(¶ms)350 So(err, ShouldBeNil)351 So(len(pipeline), ShouldEqual, 8)352 Convey("the $match task query should have the test names included", func() {353 So(pipeline[0], ShouldContainKey, "$match")354 taskMatchQuery := bson.M{355 "$or": []bson.M{356 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},357 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{358 "$ne": true,359 },360 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{361 "$ne": evergreen.CommandTypeSystem,362 }}},363 task.ProjectKey: "project",364 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},365 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},366 task.RevisionOrderNumberKey: bson.M{"$lte": 1, "$gt": 1},367 }368 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)369 })370 Convey("the $match test query should have the test names included", func() {371 So(pipeline[4], ShouldContainKey, "$match")372 testMatchQuery := bson.M{373 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},374 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},375 }376 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)377 })378 })379 })380 Convey("with adding in an after date and validating", func() {381 now := time.Now()382 params.AfterDate = now383 So(params.SetDefaultsAndValidate(), ShouldBeNil)384 Convey("the pipeline should be created properly", func() {385 pipeline, err := buildTestHistoryQuery(¶ms)386 So(err, ShouldBeNil)387 So(len(pipeline), ShouldEqual, 8)388 Convey("the $match task query should have the test names included", func() {389 So(pipeline[0], ShouldContainKey, "$match")390 taskMatchQuery := bson.M{391 "$or": []bson.M{392 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},393 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{394 "$ne": true,395 },396 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{397 "$ne": evergreen.CommandTypeSystem,398 }}},399 task.ProjectKey: "project",400 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},401 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},402 task.StartTimeKey: bson.M{"$gte": now},403 }404 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)405 })406 Convey("the $match test query should have the test names included", func() {407 So(pipeline[4], ShouldContainKey, "$match")408 testMatchQuery := bson.M{409 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},410 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},411 }412 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)413 })414 })415 })416 Convey("with adding in a before date and validating", func() {417 now := time.Now()418 params.BeforeDate = now419 So(params.SetDefaultsAndValidate(), ShouldBeNil)420 Convey("the pipeline should be created properly", func() {421 pipeline, err := buildTestHistoryQuery(¶ms)422 So(err, ShouldBeNil)423 So(len(pipeline), ShouldEqual, 8)424 Convey("the $match task query should have the test names included", func() {425 So(pipeline[0], ShouldContainKey, "$match")426 taskMatchQuery := bson.M{427 "$or": []bson.M{428 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},429 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{430 "$ne": true,431 },432 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{433 "$ne": evergreen.CommandTypeSystem,434 }}},435 task.ProjectKey: "project",436 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},437 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},438 task.StartTimeKey: bson.M{"$lte": now},439 }440 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)441 })442 Convey("the $match test query should have the test names included", func() {443 So(pipeline[4], ShouldContainKey, "$match")444 testMatchQuery := bson.M{445 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},446 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},447 }448 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)449 })450 })451 })452 Convey("with adding in an after date and before date and validating", func() {453 now := time.Now()454 params.AfterDate = now455 params.BeforeDate = now456 So(params.SetDefaultsAndValidate(), ShouldBeNil)457 Convey("the pipeline should be created properly", func() {458 pipeline, err := buildTestHistoryQuery(¶ms)459 So(err, ShouldBeNil)460 So(len(pipeline), ShouldEqual, 8)461 Convey("the $match task query should have the test names included", func() {462 So(pipeline[0], ShouldContainKey, "$match")463 taskMatchQuery := bson.M{464 "$or": []bson.M{465 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},466 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{467 "$ne": true,468 },469 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{470 "$ne": evergreen.CommandTypeSystem,471 }}},472 task.ProjectKey: "project",473 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},474 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},475 task.StartTimeKey: bson.M{"$gte": now, "$lte": now},476 }477 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)478 })479 Convey("the $match test query should have the test names included", func() {480 So(pipeline[4], ShouldContainKey, "$match")481 testMatchQuery := bson.M{482 testResultsKey + "." + task.TestResultStatusKey: bson.M{"$in": []string{evergreen.TestFailedStatus}},483 testResultsKey + "." + task.TestResultTestFileKey: bson.M{"$in": []string{"test1"}},484 }485 So(pipeline[4]["$match"], ShouldResemble, testMatchQuery)486 })487 })488 })489 Convey("with timeout in task status in the test history parameters", func() {490 params.TaskStatuses = []string{TaskTimeout}491 So(params.SetDefaultsAndValidate(), ShouldBeNil)492 Convey("the pipeline should be created without any errors", func() {493 pipeline, err := buildTestHistoryQuery(¶ms)494 So(err, ShouldBeNil)495 So(len(pipeline), ShouldEqual, 8)496 Convey("the $match task query should have timeouts included", func() {497 So(pipeline[0], ShouldContainKey, "$match")498 taskMatchQuery := bson.M{499 "$or": []bson.M{500 bson.M{501 task.StatusKey: evergreen.TaskFailed,502 task.DetailsKey + "." + task.TaskEndDetailTimedOut: true,503 }},504 task.ProjectKey: "project",505 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},506 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},507 }508 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)509 })510 })511 })512 Convey("with system failure in task status in the test history parameters", func() {513 params.TaskStatuses = []string{TaskSystemFailure}514 So(params.SetDefaultsAndValidate(), ShouldBeNil)515 Convey("the pipeline should be created without any errors", func() {516 pipeline, err := buildTestHistoryQuery(¶ms)517 So(err, ShouldBeNil)518 So(len(pipeline), ShouldEqual, 8)519 Convey("the $match task query should have timeouts included", func() {520 So(pipeline[0], ShouldContainKey, "$match")521 taskMatchQuery := bson.M{522 "$or": []bson.M{523 bson.M{524 task.StatusKey: evergreen.TaskFailed,525 task.DetailsKey + "." + task.TaskEndDetailType: evergreen.CommandTypeSystem,526 }},527 task.ProjectKey: "project",528 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},529 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},530 }531 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)532 })533 })534 })535 Convey("with system failure and task timeout in task status in the test history parameters", func() {536 params.TaskStatuses = []string{TaskSystemFailure, TaskTimeout}537 So(params.SetDefaultsAndValidate(), ShouldBeNil)538 Convey("the pipeline should be created without any errors", func() {539 pipeline, err := buildTestHistoryQuery(¶ms)540 So(err, ShouldBeNil)541 So(len(pipeline), ShouldEqual, 8)542 Convey("the $match task query should have timeouts included", func() {543 So(pipeline[0], ShouldContainKey, "$match")544 taskMatchQuery := bson.M{545 "$or": []bson.M{546 bson.M{547 task.StatusKey: evergreen.TaskFailed,548 task.DetailsKey + "." + task.TaskEndDetailTimedOut: true,549 },550 bson.M{551 task.StatusKey: evergreen.TaskFailed,552 task.DetailsKey + "." + task.TaskEndDetailType: evergreen.CommandTypeSystem,553 },554 },555 task.ProjectKey: "project",556 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},557 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},558 }559 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)560 })561 })562 })563 Convey("with normal task statuses, system failure and task timeout in task status in the test history parameters", func() {564 params.TaskStatuses = []string{TaskSystemFailure, TaskTimeout, evergreen.TaskFailed}565 So(params.SetDefaultsAndValidate(), ShouldBeNil)566 Convey("the pipeline should be created without any errors", func() {567 pipeline, err := buildTestHistoryQuery(¶ms)568 So(err, ShouldBeNil)569 So(len(pipeline), ShouldEqual, 8)570 Convey("the $match task query should have timeouts included", func() {571 So(pipeline[0], ShouldContainKey, "$match")572 taskMatchQuery := bson.M{573 "$or": []bson.M{574 bson.M{task.StatusKey: bson.M{"$in": []string{evergreen.TaskFailed}},575 task.DetailsKey + "." + task.TaskEndDetailTimedOut: bson.M{576 "$ne": true,577 },578 task.DetailsKey + "." + task.TaskEndDetailType: bson.M{579 "$ne": evergreen.CommandTypeSystem,580 }},581 bson.M{582 task.StatusKey: evergreen.TaskFailed,583 task.DetailsKey + "." + task.TaskEndDetailTimedOut: true,584 },585 bson.M{586 task.StatusKey: evergreen.TaskFailed,587 task.DetailsKey + "." + task.TaskEndDetailType: evergreen.CommandTypeSystem,588 },589 },590 task.ProjectKey: "project",591 task.DisplayNameKey: bson.M{"$in": []string{"task1", "task2"}},592 task.BuildVariantKey: bson.M{"$in": []string{"osx"}},593 }594 So(pipeline[0]["$match"], ShouldResemble, taskMatchQuery)595 })596 })597 })598 })599 })600 })601}602func TestGetTestHistory(t *testing.T) {603 assert := assert.New(t)604 testFuncs := []func(*TestHistoryParameters) ([]TestHistoryResult, error){605 GetTestHistory,606 GetTestHistoryV2,607 }608 for _, testFunc := range testFuncs {609 require.NoError(t, db.ClearCollections(task.Collection, VersionCollection, testresult.Collection))610 project := "proj"611 now := time.Now()612 testVersion := Version{613 Id: "testVersion",614 Revision: "fgh",615 RevisionOrderNumber: 1,616 Identifier: project,617 Requester: evergreen.RepotrackerVersionRequester,618 }619 assert.NoError(testVersion.Insert())620 testVersion2 := Version{621 Id: "anotherVersion",622 Revision: "def",623 RevisionOrderNumber: 2,624 Identifier: project,625 Requester: evergreen.RepotrackerVersionRequester,626 }627 assert.NoError(testVersion2.Insert())628 testVersion3 := Version{629 Id: "testV",630 Revision: "abcd",631 RevisionOrderNumber: 4,632 Identifier: project,633 Requester: evergreen.RepotrackerVersionRequester,634 }635 assert.NoError(testVersion3.Insert())636 task1 := task.Task{637 Id: "task1",638 DisplayName: "test",639 BuildVariant: "osx",640 Project: project,641 StartTime: now,642 RevisionOrderNumber: 1,643 Status: evergreen.TaskFailed,644 }645 assert.NoError(task1.Insert())646 testresults1 := []testresult.TestResult{647 testresult.TestResult{648 TaskID: task1.Id,649 Execution: task1.Execution,650 Status: evergreen.TestFailedStatus,651 TestFile: "test1",652 },653 testresult.TestResult{654 TaskID: task1.Id,655 Execution: task1.Execution,656 Status: evergreen.TestSucceededStatus,657 TestFile: "test2",658 },659 }660 assert.NoError(testresult.InsertMany(testresults1))661 task2 := task.Task{662 Id: "task2",663 DisplayName: "test",664 BuildVariant: "osx",665 Project: project,666 StartTime: now.Add(30 * time.Minute),667 RevisionOrderNumber: 2,668 Status: evergreen.TaskFailed,669 }670 assert.NoError(task2.Insert())671 testresults2 := []testresult.TestResult{672 testresult.TestResult{673 TaskID: task2.Id,674 Execution: task2.Execution,675 Status: evergreen.TestFailedStatus,676 TestFile: "test1",677 },678 testresult.TestResult{679 TaskID: task2.Id,680 Execution: task2.Execution,681 Status: evergreen.TestFailedStatus,682 TestFile: "test2",683 },684 }685 assert.NoError(testresult.InsertMany(testresults2))686 task3 := task.Task{687 Id: "task3",688 DisplayName: "test2",689 BuildVariant: "osx",690 Project: project,691 StartTime: now,692 RevisionOrderNumber: 1,693 Status: evergreen.TaskFailed,694 LocalTestResults: []task.TestResult{695 task.TestResult{696 Status: evergreen.TestFailedStatus,697 TestFile: "test1",698 },699 task.TestResult{700 Status: evergreen.TestSucceededStatus,701 TestFile: "test3",702 },703 task.TestResult{704 Status: evergreen.TestSilentlyFailedStatus,705 TestFile: "test4",706 },707 },708 }709 assert.NoError(task3.Insert())710 testresults3 := []testresult.TestResult{711 testresult.TestResult{712 TaskID: task3.Id,713 Execution: task3.Execution,714 Status: evergreen.TestFailedStatus,715 TestFile: "test1",716 },717 testresult.TestResult{718 TaskID: task3.Id,719 Execution: task3.Execution,720 Status: evergreen.TestSucceededStatus,721 TestFile: "test3",722 },723 testresult.TestResult{724 TaskID: task3.Id,725 Execution: task3.Execution,726 Status: evergreen.TestSilentlyFailedStatus,727 TestFile: "test4",728 },729 }730 assert.NoError(testresult.InsertMany(testresults3))731 // retrieving the task history with just a task name in the parameters should return relevant results732 params := TestHistoryParameters{733 TaskNames: []string{"test"},734 Project: project,735 Sort: 1,736 TaskStatuses: []string{evergreen.TaskFailed},737 TestStatuses: []string{evergreen.TestSucceededStatus, evergreen.TestFailedStatus},738 Limit: 20,739 }740 assert.NoError(params.SetDefaultsAndValidate())741 testResults, err := testFunc(¶ms)742 require.NoError(t, err)743 require.Len(t, testResults, 4)744 // the order of the test results should be in sorted order745 assert.Equal("task1", testResults[0].TaskId)746 assert.Equal("task1", testResults[1].TaskId)747 assert.Equal("task2", testResults[2].TaskId)748 assert.Equal("task2", testResults[3].TaskId)749 // with a sort of -1, the order should be in reverse revision order number order750 params.Sort = -1751 testResults, err = testFunc(¶ms)752 assert.NoError(err)753 assert.Len(testResults, 4)754 //the order of the test results should be in reverse revision number order755 assert.Equal("task2", testResults[0].TaskId)756 assert.Equal("task1", testResults[3].TaskId)757 // retrieving the task history for just a set of test names in the parameters should return relevant results758 params = TestHistoryParameters{759 TestNames: []string{"test1"},760 Project: project,761 Limit: 20,762 }763 assert.NoError(params.SetDefaultsAndValidate())764 testResults, err = testFunc(¶ms)765 assert.NoError(err)766 assert.Len(testResults, 3)767 // including a filter on a before revision should return inclusive results768 params = TestHistoryParameters{769 TaskNames: []string{"test"},770 Project: project,771 Sort: 1,772 BeforeRevision: testVersion2.Revision,773 }774 assert.NoError(params.SetDefaultsAndValidate())775 testResults, err = testFunc(¶ms)776 assert.NoError(err)777 assert.Len(testResults, 3)778 assert.Equal("task1", testResults[0].TaskId)779 // including a filter on an after revision, should only return exclusive results780 params = TestHistoryParameters{781 TaskNames: []string{"test"},782 Project: project,783 Sort: 1,784 AfterRevision: testVersion.Revision,785 }786 assert.NoError(params.SetDefaultsAndValidate())787 testResults, err = testFunc(¶ms)788 assert.NoError(err)789 assert.Len(testResults, 2)790 assert.Equal("task2", testResults[0].TaskId)791 // including a filter on both before and after revision should return relevant results792 params = TestHistoryParameters{793 TaskNames: []string{"test"},794 Project: project,795 Sort: 1,796 BeforeRevision: testVersion2.Revision,797 AfterRevision: testVersion.Revision,798 }799 assert.NoError(params.SetDefaultsAndValidate())800 testResults, err = testFunc(¶ms)801 assert.NoError(err)802 assert.Len(testResults, 2)803 assert.Equal("task2", testResults[0].TaskId)804 // including a filter on a before start time should return relevant results805 params = TestHistoryParameters{806 TaskNames: []string{"test"},807 Project: project,808 BeforeDate: now.Add(15 * time.Minute),809 Limit: 20,810 }811 assert.NoError(params.SetDefaultsAndValidate())812 testResults, err = testFunc(¶ms)813 assert.NoError(err)814 assert.Len(testResults, 1)815 // including a filter on an after start time should return relevant results816 params = TestHistoryParameters{817 TaskNames: []string{"test"},818 Project: project,819 AfterDate: now,820 Limit: 20,821 }822 assert.NoError(params.SetDefaultsAndValidate())823 testResults, err = testFunc(¶ms)824 assert.NoError(err)825 assert.Len(testResults, 3)826 // including a filter on test status of 'silentfail' should return relevant results827 params = TestHistoryParameters{828 Project: project,829 TaskNames: []string{"test2"},830 TestStatuses: []string{evergreen.TestSilentlyFailedStatus},831 Limit: 20,832 }833 assert.NoError(params.SetDefaultsAndValidate())834 testResults, err = testFunc(¶ms)835 assert.NoError(err)836 assert.Len(testResults, 1)837 // with a task with a different build variant838 anotherBV := task.Task{839 Id: "task5",840 DisplayName: "test",841 BuildVariant: "bv2",842 Project: project,843 StartTime: now,844 RevisionOrderNumber: 2,845 Status: evergreen.TaskFailed,846 }847 assert.NoError(anotherBV.Insert())848 anotherBVresults := []testresult.TestResult{849 testresult.TestResult{850 TaskID: anotherBV.Id,851 Execution: anotherBV.Execution,852 Status: evergreen.TestFailedStatus,853 TestFile: "test1",854 },855 testresult.TestResult{856 TaskID: anotherBV.Id,857 Execution: anotherBV.Execution,858 Status: evergreen.TestFailedStatus,859 TestFile: "test2",860 },861 }862 assert.NoError(testresult.InsertMany(anotherBVresults))863 // including a filter on build variant should only return test results with that build variant864 params = TestHistoryParameters{865 TaskNames: []string{"test"},866 Project: project,867 BuildVariants: []string{"bv2"},868 Limit: 20,869 }870 assert.NoError(params.SetDefaultsAndValidate())871 testResults, err = testFunc(¶ms)872 assert.NoError(err)873 assert.Len(testResults, 2)874 // not having the filter should return all results875 params = TestHistoryParameters{876 TaskNames: []string{"test"},877 Project: project,878 Limit: 20,879 }880 assert.NoError(params.SetDefaultsAndValidate())881 testResults, err = testFunc(¶ms)882 assert.NoError(err)883 assert.Len(testResults, 5)884 // using a task with no test results885 noResults := task.Task{886 Id: "noResults",887 DisplayName: "anothertest",888 BuildVariant: "bv2",889 Project: project,890 StartTime: now,891 RevisionOrderNumber: 2,892 Status: evergreen.TaskFailed,893 }894 assert.NoError(noResults.Insert())895 params = TestHistoryParameters{896 TaskNames: []string{"anothertest"},897 Project: project,898 Limit: 20,899 }900 assert.NoError(params.SetDefaultsAndValidate())901 testResults, err = testFunc(¶ms)902 assert.NoError(err)903 assert.Empty(testResults)904 // with tasks with different ordered test results905 diffOrder := task.Task{906 Id: "anotherTaskId",907 DisplayName: "testTask",908 Project: project,909 StartTime: now,910 RevisionOrderNumber: 2,911 Status: evergreen.TaskFailed,912 }913 assert.NoError(diffOrder.Insert())914 diffOrderResults := []testresult.TestResult{915 testresult.TestResult{916 TaskID: diffOrder.Id,917 Execution: diffOrder.Execution,918 Status: evergreen.TestFailedStatus,919 TestFile: "test2",920 },921 testresult.TestResult{922 TaskID: diffOrder.Id,923 Execution: diffOrder.Execution,924 Status: evergreen.TestFailedStatus,925 TestFile: "test1",926 },927 }928 assert.NoError(testresult.InsertMany(diffOrderResults))929 diffOrder2 := task.Task{930 Id: "anotherTaskId2",931 DisplayName: "testTask",932 Project: project,933 StartTime: now,934 RevisionOrderNumber: 1,935 Status: evergreen.TaskFailed,936 }937 assert.NoError(diffOrder2.Insert())938 diffOrder2Results := []testresult.TestResult{939 testresult.TestResult{940 TaskID: diffOrder2.Id,941 Execution: diffOrder2.Execution,942 Status: evergreen.TestFailedStatus,943 TestFile: "test1",944 },945 testresult.TestResult{946 TaskID: diffOrder2.Id,947 Execution: diffOrder2.Execution,948 Status: evergreen.TestFailedStatus,949 TestFile: "test2",950 },951 }952 assert.NoError(testresult.InsertMany(diffOrder2Results))953 // the order of the tests should be the same954 params = TestHistoryParameters{955 TaskNames: []string{"testTask"},956 Project: project,957 Limit: 20,958 }959 assert.NoError(params.SetDefaultsAndValidate())960 testResults, err = testFunc(¶ms)961 assert.NoError(err)962 assert.Len(testResults, 4)963 assert.Equal("anotherTaskId", testResults[0].TaskId)964 assert.Equal("test2", testResults[0].TestFile)965 assert.Equal("anotherTaskId", testResults[1].TaskId)966 assert.Equal("test1", testResults[1].TestFile)967 assert.Equal("anotherTaskId2", testResults[2].TaskId)968 assert.Equal("test2", testResults[2].TestFile)969 assert.Equal("anotherTaskId2", testResults[3].TaskId)970 assert.Equal("test1", testResults[3].TestFile)971 // using test parameter with a task status with timeouts972 timedOutTask := task.Task{973 Id: "timeout",974 DisplayName: "test",975 Project: project,976 StartTime: now,977 RevisionOrderNumber: 1,978 Status: evergreen.TaskFailed,979 Details: apimodels.TaskEndDetail{980 TimedOut: true,981 },982 }983 assert.NoError(timedOutTask.Insert())984 timedOutResults := testresult.TestResult{985 TaskID: timedOutTask.Id,986 Execution: timedOutTask.Execution,987 Status: evergreen.TestFailedStatus,988 TestFile: "test2",989 }990 assert.NoError(testresult.InsertMany([]testresult.TestResult{timedOutResults}))991 params = TestHistoryParameters{992 Project: project,993 TaskNames: []string{"test"},994 TaskStatuses: []string{TaskTimeout},995 Limit: 20,996 }997 assert.NoError(params.SetDefaultsAndValidate())998 testResults, err = testFunc(¶ms)999 assert.NoError(err)1000 assert.Len(testResults, 1)1001 // using test parameter with a task status with system failures1002 systemFailureTask := task.Task{1003 Id: "systemfailed",1004 DisplayName: "test",1005 Project: project,1006 StartTime: now,1007 RevisionOrderNumber: 1,1008 Status: evergreen.TaskFailed,1009 Details: apimodels.TaskEndDetail{1010 Type: evergreen.CommandTypeSystem,1011 },1012 }1013 assert.NoError(systemFailureTask.Insert())1014 systemFailureResult := testresult.TestResult{1015 TaskID: systemFailureTask.Id,1016 Execution: systemFailureTask.Execution,1017 Status: evergreen.TestFailedStatus,1018 TestFile: "test2",1019 }1020 assert.NoError(testresult.InsertMany([]testresult.TestResult{systemFailureResult}))1021 params = TestHistoryParameters{1022 Project: project,1023 TaskNames: []string{"test"},1024 TaskStatuses: []string{TaskSystemFailure},1025 Limit: 20,1026 }1027 assert.NoError(params.SetDefaultsAndValidate())1028 testResults, err = testFunc(¶ms)1029 assert.NoError(err)1030 assert.Len(testResults, 1)1031 assert.Equal("test2", testResults[0].TestFile)1032 assert.Equal(evergreen.CommandTypeSystem, testResults[0].TaskDetailsType)1033 }1034 // succeeded tasks should always be returned if asked for (only implemented in V2)1035 successfulTask := task.Task{1036 Id: "success",1037 DisplayName: "test",1038 Project: "proj",1039 StartTime: time.Now(),1040 RevisionOrderNumber: 1,1041 Status: evergreen.TaskSucceeded,1042 Details: apimodels.TaskEndDetail{1043 Type: evergreen.CommandTypeSystem,1044 },1045 }1046 assert.NoError(successfulTask.Insert())1047 successfulResult := testresult.TestResult{1048 TaskID: successfulTask.Id,1049 Execution: successfulTask.Execution,1050 Status: evergreen.TestSucceededStatus,1051 TestFile: "test1",1052 }1053 assert.NoError(testresult.InsertMany([]testresult.TestResult{successfulResult}))1054 params := TestHistoryParameters{1055 Project: "proj",1056 TaskNames: []string{"test"},1057 TaskStatuses: []string{evergreen.TaskSucceeded},1058 TestStatuses: []string{evergreen.TestSucceededStatus},1059 Limit: 10,1060 }1061 assert.NoError(params.SetDefaultsAndValidate())1062 testResults, err := GetTestHistoryV2(¶ms)1063 assert.NoError(err)1064 assert.Len(testResults, 1)1065 assert.Equal(successfulResult.TestFile, testResults[0].TestFile)1066 assert.Equal(successfulTask.Id, testResults[0].TaskId)1067}1068func TestTaskHistoryPickaxe(t *testing.T) {1069 require.NoError(t, db.ClearCollections(task.Collection, testresult.Collection, RepositoriesCollection))1070 assert := assert.New(t)1071 proj := Project{1072 Identifier: "proj",...
test_test.go
Source:test_test.go
...108 testResult := testresult.TestResult{ID: testID, TaskID: "task_2"}109 assert.NoError(testResult.Insert())110 for i := 0; i < numTasks; i++ {111 taskId := fmt.Sprintf("task_%d", i)112 foundTests, err := serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})113 assert.NoError(err)114 assert.Len(foundTests, numTests)115 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{"pass"}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})116 assert.NoError(err)117 assert.Len(foundTests, numTests/2)118 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{"fail"}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})119 assert.NoError(err)120 assert.Len(foundTests, numTests/2)121 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "TestSuite/TestNum1", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})122 assert.NoError(err)123 assert.Len(foundTests, 1)124 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "TestSuite/TestNum2", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})125 assert.NoError(err)126 assert.Len(foundTests, 1)127 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 0, Limit: 5, Execution: 0})128 assert.NoError(err)129 assert.Len(foundTests, 5)130 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 1, Limit: 5, Execution: 0})131 assert.NoError(err)132 assert.Len(foundTests, 5)133 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: 1, Page: 2, Limit: 5, Execution: 0})134 assert.NoError(err)135 assert.Len(foundTests, 0)136 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "test_file", GroupID: "", SortDir: -1, Page: 0, Limit: 0, Execution: 0})137 assert.NoError(err)138 for i := range foundTests {139 assert.True(foundTests[i].TestFile == testObjects[last-i])140 }141 assert.Len(foundTests, 10)142 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "duration", GroupID: "", SortDir: -1, Page: 0, Limit: 0, Execution: 0})143 assert.NoError(err)144 for i, test := range foundTests {145 assert.True(test.EndTime == float64(last-i))146 }147 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})148 assert.NoError(err)149 for i, test := range foundTests {150 assert.True(test.EndTime == float64(i))151 }152 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{"pa"}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})153 assert.NoError(err)154 assert.Len(foundTests, 0)155 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{"not_a_real_status"}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})156 assert.NoError(err)157 assert.Len(foundTests, 0)158 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "fail", Statuses: []string{"pass"}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})159 assert.NoError(err)160 assert.Len(foundTests, 0)161 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{"pass", "fail"}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})162 assert.NoError(err)163 assert.Len(foundTests, 10)164 }165 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TestID: string(testID), TaskID: "task_2"})166 assert.NoError(err)167 assert.Len(foundTests, 1)168 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: "fake_task", TestName: "", Statuses: []string{}, SortBy: "duration", GroupID: "", SortDir: 1, Page: 0, Limit: 0, Execution: 0})169 assert.NoError(err)170 assert.Len(foundTests, 0)171 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: "task_0", TestName: "", Statuses: []string{"pass", "fail"}, SortBy: "duration", GroupID: "group_0", SortDir: 1, Page: 0, Limit: 0, Execution: 0})172 assert.NoError(err)173 assert.Len(foundTests, 10)174 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: "task_0", TestName: "", Statuses: []string{"pass", "fail"}, SortBy: "duration", GroupID: "unreal-group-id", SortDir: 1, Page: 0, Limit: 0, Execution: 0})175 assert.NoError(err)176 assert.Len(foundTests, 0)177}178func TestFindTestsByTaskIdPaginationOrderDependsOnObjectId(t *testing.T) {179 assert := assert.New(t)180 assert.NoError(db.ClearCollections(task.Collection, testresult.Collection))181 serviceContext := &DBTestConnector{}182 taskId := "TaskOne"183 Task := &task.Task{184 Id: taskId,185 }186 idOne := mgobson.ObjectIdHex("507f191e810c19729de860ea")187 idTwo := mgobson.ObjectIdHex("407f191e810c19729de860ea")188 idThree := mgobson.ObjectIdHex("307f191e810c19729de860ea")189 tests := []testresult.TestResult{190 testresult.TestResult{191 ID: idOne,192 TaskID: taskId,193 Execution: 0,194 Status: "pass",195 }, testresult.TestResult{196 ID: idTwo,197 TaskID: taskId,198 Execution: 0,199 Status: "pass",200 }, testresult.TestResult{201 ID: idThree,202 TaskID: taskId,203 Execution: 0,204 Status: "pass",205 },206 }207 assert.NoError(Task.Insert())208 for _, test := range tests {209 assert.NoError(test.Insert())210 }211 foundTests, err := serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "status", GroupID: "", SortDir: 1, Page: 0, Limit: 1, Execution: 0})212 assert.NoError(err)213 assert.Len(foundTests, 1)214 assert.True(foundTests[0].ID == idThree)215 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "status", GroupID: "", SortDir: 1, Page: 1, Limit: 1, Execution: 0})216 assert.NoError(err)217 assert.Len(foundTests, 1)218 assert.True(foundTests[0].ID == idTwo)219 foundTests, err = serviceContext.FindTestsByTaskId(FindTestsByTaskIdOpts{TaskID: taskId, TestName: "", Statuses: []string{}, SortBy: "status", GroupID: "", SortDir: 1, Page: 2, Limit: 1, Execution: 0})220 assert.NoError(err)221 assert.Len(foundTests, 1)222 assert.True(foundTests[0].ID == idOne)223}224func TestFindTestsByDisplayTaskId(t *testing.T) {225 assert := assert.New(t)226 assert.NoError(db.ClearCollections(task.Collection, testresult.Collection))227 serviceContext := &DBTestConnector{}228 numTests := 10229 numTasks := 2230 testObjects := make([]string, numTests)231 for ix := range testObjects {232 testObjects[ix] = fmt.Sprintf("object_id_%d_", ix)233 }...
testresults_test.go
Source:testresults_test.go
...11 input *dbex.Testresult12 isBroken bool13}14var fkTestresultsTestpoints dbex.Testpoint = dbex.Testpoint{Id: 550, TestEngineerId: 550, Tester: fkTestpointsTesters, TestCaseId: 550, Testcase: fkTestpointsTestcases, TestSetId: 550, Testset: fkTestpointsTestsets}15var fkTestresultsStatuses dbex.Status = dbex.Status{Id: 550, Status: "fk"}16func TestCreateTestresult(t *testing.T) {17 dataItems := []TestDataItemTestresults{18 {100, &dbex.Testresult{Id: 100, TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}, false},19 {200, &dbex.Testresult{Id: 200, TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses}, true},20 {300, &dbex.Testresult{Id: 100, TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}, true},21 {300, &dbex.Testresult{Id: 400, Start: time.Now(), Finish: time.Now()}, true},22 }23 for _, item := range dataItems {24 err := DB.CreateTestresult(item.input)25 if item.isBroken {26 if err == nil {27 t.Error("\nFAILED: expected an error, but no error catched at Inserting ", item.input)28 }29 } else {30 if err != nil {31 t.Error("\nFAILED: non-expected error at Inserting ", item.input, "\nerror: ", err)32 }33 }34 }35 if err := DB.DB.Exec("delete from testresults").Error; err != nil {36 t.Error("Clear table error:", err)37 }38}39func TestDeleteTestresultById(t *testing.T) {40 bar := &dbex.Testresult{TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}41 err := DB.CreateTestresult(bar)42 if err != nil {43 t.Error("FAILED: insert error: ", err, bar)44 }45 foo := &dbex.Testresult{}46 err = DB.DB.First(foo, bar.Id).Error47 if errors.Is(err, gorm.ErrRecordNotFound) {48 t.Error("FAILED: not found record")49 } else if err != nil {50 t.Error("FAILED: some error : ", err, "\nfoo: ", foo)51 }52 err = DB.DeleteTestresultById(foo.Id)53 if err != nil {54 t.Error("\nFAILED: non-expected error at Delete by id ", foo.Id, "\nerror: ", err)55 }56 foo = &dbex.Testresult{}57 err = DB.DB.First(foo, bar.Id).Error58 if errors.Is(err, gorm.ErrRecordNotFound) {59 // passed60 } else if err != nil {61 t.Error("FAILED: some error : ", err, "\nfoo: ", foo)62 } else {63 t.Error("FAILED: record not deleted")64 }65 if err := DB.DB.Exec("delete from testresults").Error; err != nil {66 t.Error("Clear table error:", err)67 }68}69func TestUpdateTestresult(t *testing.T) {70 bar := &dbex.Testresult{TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}71 err := DB.CreateTestresult(bar)72 if err != nil {73 t.Error("FAILED: insert error: ", err, bar)74 }75 foo := &dbex.Testresult{}76 err = DB.DB.First(foo, bar.Id).Error77 if errors.Is(err, gorm.ErrRecordNotFound) {78 t.Error("FAILED: not found record")79 } else if err != nil {80 t.Error("FAILED: some error : ", err, "\nfoo: ", foo)81 }82 foo.StatusId = 55183 foo.Status = dbex.Status{Id: 551, Status: "fk"}84 err = DB.UpdateTestresult(foo)85 if err != nil {86 t.Error("\nFAILED: non-expected error at Update ", foo.Id, "\nerror: ", err)87 }88 foo = &dbex.Testresult{}89 err = DB.DB.First(foo, bar.Id).Error90 if errors.Is(err, gorm.ErrRecordNotFound) {91 t.Error("FAILED: not found record")92 } else if err != nil {93 t.Error("FAILED: some error : ", err, "\nfoo: ", foo)94 } else if foo.StatusId != 551 {95 t.Error("FAILED: was not updated")96 }97 if err := DB.DB.Exec("delete from testresults").Error; err != nil {98 t.Error("Clear table error:", err)99 }100}101func TestSelectAllTestresults(t *testing.T) {102 // clear table103 if err := DB.DB.Exec("delete from testresults").Error; err != nil {104 t.Error("Clear table error:", err)105 }106 dataItems := []TestDataItemTestresults{107 {0, &dbex.Testresult{TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}, false},108 {0, &dbex.Testresult{TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}, false},109 {0, &dbex.Testresult{TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}, false},110 }111 for _, item := range dataItems {112 err := DB.CreateTestresult(item.input)113 if err != nil {114 t.Error("\nFAILED: non-expected error at Inserting ", item.input, "\nerror: ", err)115 }116 }117 foo, err := DB.SelectAllTestresults()118 if err != nil {119 t.Error("\nFAILED: non-expected error at SelectAll\nerror: ", err)120 } else if len(foo) == 0 {121 t.Error("\nFAILED: returned empty slice at SelectAll")122 }123 if len(foo) != len(dataItems) {124 t.Error("\nFAILED: returned count not match")125 }126 for i, item := range foo {127 if item.Id != dataItems[i].input.Id {128 t.Error("\nFAILED: returned id is not match ", item.Id, dataItems[i].input.Id)129 }130 }131 if err := DB.DB.Exec("delete from testresults").Error; err != nil {132 t.Error("Clear table error:", err)133 }134}135func TestSelectTestresultById(t *testing.T) {136 bar := &dbex.Testresult{Id: 500, TestPointId: 550, Testpoint: fkTestresultsTestpoints, StatusId: 550, Status: fkTestresultsStatuses, Start: time.Now(), Finish: time.Now()}137 err := DB.CreateTestresult(bar)138 if err != nil {139 t.Error("FAILED: insert error: ", err)140 }141 foo := &dbex.Testresult{}142 err = DB.DB.First(foo, bar.Id).Error143 if errors.Is(err, gorm.ErrRecordNotFound) {144 t.Error("FAILED: not found record")145 } else if err != nil {146 t.Error("FAILED: some error : ", err, "\nfoo: ", foo)147 }148 if err := DB.DB.Exec("delete from testresults").Error; err != nil {149 t.Error("Clear table error:", err)150 }...
Statuses
Using AI Code Generation
1import (2func main() {3 caps := selenium.Capabilities{"browserName": "chrome"}4 caps.AddChrome(chrome.Capabilities{5 Args: []string{6 },7 })8 if err != nil {9 panic(err)10 }11 defer wd.Quit()12 panic(err)13 }14 elem, err := wd.FindElement(selenium.ByCSSSelector, "input[name=q]")15 if err != nil {16 panic(err)17 }18 if err := elem.SendKeys("Cheese!"); err != nil {19 panic(err)20 }21 if err := elem.Submit(); err != nil {22 panic(err)23 }24 time.Sleep(5 * time.Second)25 title, err := wd.Title()26 if err != nil {27 panic(err)28 }29 if !strings.HasPrefix(title, "Cheese!") {30 panic(fmt.Sprintf("got title %q, want %q", title, "Cheese!"))31 }32 source, err := wd.PageSource()33 if err != nil {34 panic(err)35 }36 fmt.Println(source)37}382019/09/05 13:28:50 [DEBUG] [HTTP] {"desiredCapabilities":{"browserName":"chrome","
Statuses
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 testsuite := testsuite.New("test suite", true, true)5 testsuite.AddSpecsFromNode(1, 1, "1.go")6 testsuite.AddSpecsFromNode(2, 1, "2.go")7 testsuite.Run()8 for _, testresult := range testsuite.Results {9 fmt.Println(testresult.Statuses())10 }11}
Statuses
Using AI Code Generation
1import (2func main() {3 selenium.SetDebug(true)4 service, err := selenium.NewChromeDriverService("chromedriver", port)5 if err != nil {6 log.Fatal(err)7 }8 defer service.Stop()9 caps := selenium.Capabilities{"browserName": "chrome"}10 caps.AddChrome(chrome.Capabilities{11 Args: []string{12 },13 })14 if err != nil {15 log.Fatal(err)16 }17 defer wd.Quit()18 log.Fatal(err)19 }20"); err != nil {
Statuses
Using AI Code Generation
1import (2type TestResult struct {3}4func main() {5 files, err := ioutil.ReadDir("/Users/roshni/Desktop/GoLang/Assignment2/testcases")6 if err != nil {7 log.Fatal(err)8 }9 for _, file := range files {10 if strings.HasSuffix(file.Name(), ".in") {11 name := strings.TrimSuffix(file.Name(), filepath.Ext(file.Name()))12 cmd := exec.Command("go", "run", "/Users/roshni/Desktop/GoLang/Assignment2/"+name+".go")13 out, err := cmd.CombinedOutput()14 if err != nil {15 log.Fatal(err)16 }17 expected, err := ioutil.ReadFile("/Users/roshni/Desktop/GoLang/Assignment2/testcases/" + name + ".out")18 if err != nil {19 log.Fatal(err)20 }21 dmp := diffmatchpatch.New()22 diffs := dmp.DiffMain(string(expected), string(out), false)23 fmt.Println(dmp.DiffPrettyText(diffs))24 if string(expected) == string(out) {25 tr.Statuses = append(tr.Statuses, "PASS")26 } else {27 tr.Statuses = append(tr.Statuses, "FAIL")28 }29 }30 }31 fmt.Println(tr.Statuses)32}33import (34func main() {
Statuses
Using AI Code Generation
1import (2func main() {3 fmt.Println(testresult.Statuses())4}5import (6func main() {7 fmt.Println(testresult.Statuses())8}
Statuses
Using AI Code Generation
1import (2func main() {3 var testResults = testresult.New()4 testResults.Add("Passed")5 testResults.Add("Failed")6 testResults.Add("Failed")7 testResults.Add("Passed")8 fmt.Println(testResults.Statuses())9}10import (11func main() {12 var testResults = testresult.New()13 testResults.Add("Passed")14 testResults.Add("Failed")15 testResults.Add("Failed")16 testResults.Add("Passed")17 fmt.Println(testResults.Statuses("Passed"))18}19import (20func main() {21 var testResults = testresult.New()22 testResults.Add("Passed")23 testResults.Add("Failed")24 testResults.Add("Failed")25 testResults.Add("Passed")26 fmt.Println(testResults.Failed())27}28import (29func main() {30 var testResults = testresult.New()31 testResults.Add("Passed")32 testResults.Add("Failed")33 testResults.Add("Failed")34 testResults.Add("Passed")35 fmt.Println(testResults.Passed())36}37import (38func main() {39 var testResults = testresult.New()40 testResults.Add("Passed")41 testResults.Add("Failed")
Statuses
Using AI Code Generation
1import (2func main() {3 testResult := testresult.NewTestResult()4 statuses := testResult.Statuses()5 fmt.Printf("Statuses: %v", statuses)6}7import (8func main() {9 testResult := testresult.NewTestResult()10 statuses := testResult.Statuses()11 fmt.Printf("Statuses: %v", statuses)12}13import (14func main() {15 testResult := testresult.NewTestResult()16 statuses := testResult.Statuses()17 fmt.Printf("Statuses: %v", statuses)18}19import (20func main() {21 testResult := testresult.NewTestResult()22 statuses := testResult.Statuses()23 fmt.Printf("Statuses: %v", statuses)24}25import (26func main() {27 testResult := testresult.NewTestResult()28 statuses := testResult.Statuses()
Statuses
Using AI Code Generation
1import (2func main() {3 c, err := client.NewClient("localhost:5555")4 if err != nil {5 panic(err)6 }7 table := c.Table("testresult")8 statuses, err := table.Statuses()9 if err != nil {10 panic(err)11 }12 fmt.Println(statuses)13}14[{"name":"testresult","count":0,"size":0,"lastModified":0}]15import (16func main() {17 c, err := client.NewClient("localhost:5555")18 if err != nil {19 panic(err)20 }21 table := c.Table("testresult")22 statuses, err := table.Statuses()23 if err != nil {24 panic(err)25 }26 fmt.Println(statuses)27}28[{"name":"testresult","count":0,"size":0,"lastModified":0}]29import (30func main() {31 c, err := client.NewClient("localhost:5555")32 if err != nil {33 panic(err)34 }35 table := c.Table("testresult")36 status, err := table.Status()37 if err != nil {38 panic(err)39 }40 fmt.Println(status)41}42{"name":"testresult","count":0,"size":0,"lastModified":0}
Statuses
Using AI Code Generation
1import (2func main() {3 testResult = TestResult{4 }5 fmt.Println(testResult.Statuses("Pass"))6}7type TestResult struct {8}9func (t TestResult) Statuses(status string) []string {10 if strings.EqualFold(t.Test1Status, status) {11 result = append(result, t.Test1)12 }13 if strings.EqualFold(t.Test2Status, status) {14 result = append(result, t.Test2)15 }16 if strings.EqualFold(t.Test3Status, status) {17 result = append(result, t.Test3)18 }19 if strings.EqualFold(t.Test4Status, status) {20 result = append(result, t.Test4)21 }22}
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!!