How to use Failures method of gomock Package

Best Mock code snippet using gomock.Failures

stateless_actions_test.go

Source:stateless_actions_test.go Github

copy

Full Screen

...44 testRespoolPath = "/testPath"45 testEntityVersion = "1-1-1"46 testOpaqueData = "opaqueData"47 testMaxInstanceRetries = uint32(2)48 testMaxTolerableInstanceFailures = uint32(3)49)50type statelessActionsTestSuite struct {51 suite.Suite52 ctx context.Context53 client Client54 respoolID *v1alphapeloton.ResourcePoolID55 ctrl *gomock.Controller56 statelessClient *mocks.MockJobServiceYARPCClient57 resClient *respoolmocks.MockResourceManagerYARPCClient58 jobmgrClient *jobmgrsvcmocks.MockJobManagerServiceYARPCClient59}60func (suite *statelessActionsTestSuite) SetupTest() {61 suite.ctrl = gomock.NewController(suite.T())62 suite.statelessClient = mocks.NewMockJobServiceYARPCClient(suite.ctrl)63 suite.resClient = respoolmocks.NewMockResourceManagerYARPCClient(suite.ctrl)64 suite.jobmgrClient = jobmgrsvcmocks.NewMockJobManagerServiceYARPCClient(suite.ctrl)65 suite.ctx = context.Background()66 suite.respoolID = &v1alphapeloton.ResourcePoolID{Value: uuid.New()}67 suite.client = Client{68 Debug: false,69 statelessClient: suite.statelessClient,70 jobmgrClient: suite.jobmgrClient,71 resClient: suite.resClient,72 dispatcher: nil,73 ctx: suite.ctx,74 }75}76func (suite *statelessActionsTestSuite) TearDownTest() {77 suite.ctrl.Finish()78}79func (suite *statelessActionsTestSuite) TestStatelessGetCacheActionSuccess() {80 suite.jobmgrClient.EXPECT().81 GetJobCache(suite.ctx, &jobmgrsvc.GetJobCacheRequest{82 JobId: &v1alphapeloton.JobID{Value: testJobID},83 }).84 Return(&jobmgrsvc.GetJobCacheResponse{}, nil)85 suite.NoError(suite.client.StatelessGetCacheAction(testJobID))86}87func (suite *statelessActionsTestSuite) TestStatelessGetCacheActionError() {88 suite.jobmgrClient.EXPECT().89 GetJobCache(suite.ctx, &jobmgrsvc.GetJobCacheRequest{90 JobId: &v1alphapeloton.JobID{Value: testJobID},91 }).92 Return(nil, yarpcerrors.InternalErrorf("test error"))93 suite.Error(suite.client.StatelessGetCacheAction(testJobID))94}95func (suite *statelessActionsTestSuite) TestStatelessRefreshAction() {96 suite.jobmgrClient.EXPECT().97 RefreshJob(suite.ctx, &jobmgrsvc.RefreshJobRequest{98 JobId: &v1alphapeloton.JobID{Value: testJobID},99 }).100 Return(&jobmgrsvc.RefreshJobResponse{}, nil)101 suite.NoError(suite.client.StatelessRefreshAction(testJobID))102}103func (suite *statelessActionsTestSuite) TestStatelessRefreshActionError() {104 suite.jobmgrClient.EXPECT().105 RefreshJob(suite.ctx, &jobmgrsvc.RefreshJobRequest{106 JobId: &v1alphapeloton.JobID{Value: testJobID},107 }).108 Return(nil, yarpcerrors.InternalErrorf("test error"))109 suite.Error(suite.client.StatelessRefreshAction(testJobID))110}111func (suite *statelessActionsTestSuite) TestStatelessWorkflowPauseAction() {112 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}113 opaque := "test"114 suite.statelessClient.EXPECT().115 PauseJobWorkflow(suite.ctx, &svc.PauseJobWorkflowRequest{116 JobId: &v1alphapeloton.JobID{Value: testJobID},117 Version: entityVersion,118 OpaqueData: &v1alphapeloton.OpaqueData{Data: opaque},119 }).120 Return(&svc.PauseJobWorkflowResponse{121 Version: entityVersion,122 }, nil)123 suite.NoError(suite.client.StatelessWorkflowPauseAction(testJobID, entityVersion.GetValue(), opaque))124}125func (suite *statelessActionsTestSuite) TestStatelessWorkflowPauseActionFailure() {126 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}127 suite.statelessClient.EXPECT().128 PauseJobWorkflow(suite.ctx, &svc.PauseJobWorkflowRequest{129 JobId: &v1alphapeloton.JobID{Value: testJobID},130 Version: entityVersion,131 }).132 Return(nil, yarpcerrors.InternalErrorf("test error"))133 suite.Error(suite.client.StatelessWorkflowPauseAction(testJobID, entityVersion.GetValue(), ""))134}135func (suite *statelessActionsTestSuite) TestStatelessWorkflowResumeAction() {136 opaque := "test"137 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}138 suite.statelessClient.EXPECT().139 ResumeJobWorkflow(suite.ctx, &svc.ResumeJobWorkflowRequest{140 JobId: &v1alphapeloton.JobID{Value: testJobID},141 Version: entityVersion,142 OpaqueData: &v1alphapeloton.OpaqueData{Data: opaque},143 }).144 Return(&svc.ResumeJobWorkflowResponse{145 Version: entityVersion,146 }, nil)147 suite.NoError(suite.client.StatelessWorkflowResumeAction(testJobID, entityVersion.GetValue(), opaque))148}149func (suite *statelessActionsTestSuite) TestStatelessWorkflowResumeActionFailure() {150 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}151 suite.statelessClient.EXPECT().152 ResumeJobWorkflow(suite.ctx, &svc.ResumeJobWorkflowRequest{153 JobId: &v1alphapeloton.JobID{Value: testJobID},154 Version: entityVersion,155 }).156 Return(nil, yarpcerrors.InternalErrorf("test error"))157 suite.Error(suite.client.StatelessWorkflowResumeAction(testJobID, entityVersion.GetValue(), ""))158}159func (suite *statelessActionsTestSuite) TestStatelessWorkflowAbortAction() {160 opaque := "test"161 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}162 suite.statelessClient.EXPECT().163 AbortJobWorkflow(suite.ctx, &svc.AbortJobWorkflowRequest{164 JobId: &v1alphapeloton.JobID{Value: testJobID},165 Version: entityVersion,166 OpaqueData: &v1alphapeloton.OpaqueData{Data: opaque},167 }).168 Return(&svc.AbortJobWorkflowResponse{169 Version: entityVersion,170 }, nil)171 suite.NoError(suite.client.StatelessWorkflowAbortAction(testJobID, entityVersion.GetValue(), opaque))172}173func (suite *statelessActionsTestSuite) TestStatelessWorkflowAbortActionFailure() {174 entityVersion := &v1alphapeloton.EntityVersion{Value: testEntityVersion}175 suite.statelessClient.EXPECT().176 AbortJobWorkflow(suite.ctx, &svc.AbortJobWorkflowRequest{177 JobId: &v1alphapeloton.JobID{Value: testJobID},178 Version: entityVersion,179 }).180 Return(nil, yarpcerrors.InternalErrorf("test error"))181 suite.Error(suite.client.StatelessWorkflowAbortAction(testJobID, entityVersion.GetValue(), ""))182}183func (suite *statelessActionsTestSuite) TestStatelessQueryActionSuccess() {184 suite.statelessClient.EXPECT().185 QueryJobs(gomock.Any(), gomock.Any()).186 Do(func(ctx context.Context, req *svc.QueryJobsRequest) {187 spec := req.GetSpec()188 suite.Equal(spec.GetPagination().GetLimit(), uint32(10))189 suite.Equal(spec.GetPagination().GetMaxLimit(), uint32(0))190 suite.Equal(spec.GetPagination().GetOffset(), uint32(0))191 suite.Equal(spec.GetRespool().GetValue(), "/testPath")192 suite.Equal(spec.GetName(), "test1")193 suite.Equal(spec.GetOwner(), "owner1")194 suite.Equal(spec.GetLabels()[0].GetKey(), "k1")195 suite.Equal(spec.GetLabels()[0].GetValue(), "v1")196 suite.Equal(spec.GetLabels()[1].GetKey(), "k2")197 suite.Equal(spec.GetLabels()[1].GetValue(), "v2")198 suite.Equal(spec.GetKeywords()[0], "key1")199 suite.Equal(spec.GetKeywords()[1], "key2")200 }).201 Return(&svc.QueryJobsResponse{}, nil)202 err := suite.client.StatelessQueryAction(203 "k1=v1,k2=v2",204 "/testPath",205 "key1,key2",206 "JOB_STATE_RUNNING,JOB_STATE_SUCCEEDED",207 "owner1",208 "test1",209 1,210 10,211 0,212 0,213 "creation_time",214 "ASC",215 )216 suite.NoError(err)217}218func (suite *statelessActionsTestSuite) TestStatelessQueryActionWrongLabelFormatFailure() {219 err := suite.client.StatelessQueryAction(220 "k1,k2",221 "/testPath",222 "key1,key2",223 "JOB_STATE_RUNNING,JOB_STATE_SUCCEEDED",224 "owner1",225 "test1",226 1,227 10,228 0,229 0,230 "creation_time",231 "ASC",232 )233 suite.Error(err)234}235func (suite *statelessActionsTestSuite) TestStatelessQueryActionWrongSortOrderFailure() {236 err := suite.client.StatelessQueryAction(237 "k1=v1,k2=v2",238 "/testPath",239 "key1,key2",240 "JOB_STATE_RUNNING,JOB_STATE_SUCCEEDED",241 "owner1",242 "test1",243 1,244 10,245 0,246 0,247 "creation_time",248 "Descent",249 )250 suite.Error(err)251}252func (suite *statelessActionsTestSuite) TestStatelessQueryActionError() {253 suite.statelessClient.EXPECT().254 QueryJobs(gomock.Any(), gomock.Any()).255 Do(func(ctx context.Context, req *svc.QueryJobsRequest) {256 spec := req.GetSpec()257 suite.Equal(spec.GetPagination().GetLimit(), uint32(10))258 suite.Equal(spec.GetPagination().GetMaxLimit(), uint32(0))259 suite.Equal(spec.GetPagination().GetOffset(), uint32(0))260 suite.Equal(spec.GetRespool().GetValue(), "/testPath")261 suite.Equal(spec.GetName(), "test1")262 suite.Equal(spec.GetOwner(), "owner1")263 suite.Equal(spec.GetLabels()[0].GetKey(), "k1")264 suite.Equal(spec.GetLabels()[0].GetValue(), "v1")265 suite.Equal(spec.GetLabels()[1].GetKey(), "k2")266 suite.Equal(spec.GetLabels()[1].GetValue(), "v2")267 suite.Equal(spec.GetKeywords()[0], "key1")268 suite.Equal(spec.GetKeywords()[1], "key2")269 }).270 Return(&svc.QueryJobsResponse{}, yarpcerrors.InternalErrorf("test error"))271 err := suite.client.StatelessQueryAction(272 "k1=v1,k2=v2",273 "/testPath",274 "key1,key2",275 "JOB_STATE_RUNNING,JOB_STATE_SUCCEEDED",276 "owner1",277 "test1",278 1,279 10,280 0,281 0,282 "creation_time",283 "ASC",284 )285 suite.Error(err)286}287func (suite *statelessActionsTestSuite) TestStatelessReplaceJobActionSuccess() {288 batchSize := uint32(1)289 respoolPath := "/testPath"290 override := false291 maxInstanceRetries := uint32(2)292 maxTolerableInstanceFailures := uint32(1)293 rollbackOnFailure := false294 startPaused := true295 inPlace := false296 startPods := false297 opaque := "test"298 suite.resClient.EXPECT().299 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{300 Path: &respool.ResourcePoolPath{301 Value: respoolPath,302 },303 }).304 Return(&respool.LookupResponse{305 Id: &peloton.ResourcePoolID{Value: uuid.New()},306 }, nil)307 suite.statelessClient.EXPECT().308 GetJob(gomock.Any(), gomock.Any()).309 Return(&svc.GetJobResponse{310 Summary: &stateless.JobSummary{311 Status: &stateless.JobStatus{312 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},313 },314 },315 }, nil)316 suite.statelessClient.EXPECT().317 ReplaceJob(gomock.Any(), gomock.Any()).318 Return(&svc.ReplaceJobResponse{319 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},320 }, nil)321 suite.NoError(suite.client.StatelessReplaceJobAction(322 testJobID,323 testStatelessSpecConfig,324 batchSize,325 respoolPath,326 "",327 override,328 maxInstanceRetries,329 maxTolerableInstanceFailures,330 rollbackOnFailure,331 startPaused,332 opaque,333 inPlace,334 startPods,335 ))336}337// TestStatelessReplaceJobActionLookupResourcePoolIDFail tests the failure case of replace338// job due to look up resource pool fails339func (suite *statelessActionsTestSuite) TestStatelessReplaceJobActionLookupResourcePoolIDFail() {340 batchSize := uint32(1)341 override := false342 maxInstanceRetries := uint32(2)343 maxTolerableInstanceFailures := uint32(1)344 rollbackOnFailure := false345 startPaused := true346 inPlace := false347 startPods := false348 suite.resClient.EXPECT().349 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{350 Path: &respool.ResourcePoolPath{351 Value: testRespoolPath,352 },353 }).354 Return(nil, yarpcerrors.InternalErrorf("test error"))355 suite.Error(suite.client.StatelessReplaceJobAction(356 testJobID,357 testStatelessSpecConfig,358 batchSize,359 testRespoolPath,360 testEntityVersion,361 override,362 maxInstanceRetries,363 maxTolerableInstanceFailures,364 rollbackOnFailure,365 startPaused,366 "",367 inPlace,368 startPods,369 ))370}371// TestStatelessReplaceJobActionGetJobFail tests the failure case of replace372// job due to get job fails373func (suite *statelessActionsTestSuite) TestStatelessReplaceJobActionGetJobFail() {374 batchSize := uint32(1)375 respoolPath := "/testPath"376 override := false377 maxInstanceRetries := uint32(2)378 maxTolerableInstanceFailures := uint32(1)379 rollbackOnFailure := false380 startPaused := true381 inPlace := false382 startPods := false383 opaque := "test"384 suite.resClient.EXPECT().385 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{386 Path: &respool.ResourcePoolPath{387 Value: respoolPath,388 },389 }).390 Return(&respool.LookupResponse{391 Id: &peloton.ResourcePoolID{Value: uuid.New()},392 }, nil)393 suite.statelessClient.EXPECT().394 GetJob(gomock.Any(), gomock.Any()).395 Return(nil, yarpcerrors.InternalErrorf("test error"))396 suite.Error(suite.client.StatelessReplaceJobAction(397 testJobID,398 testStatelessSpecConfig,399 batchSize,400 respoolPath,401 "",402 override,403 maxInstanceRetries,404 maxTolerableInstanceFailures,405 rollbackOnFailure,406 startPaused,407 opaque,408 inPlace,409 startPods,410 ))411}412func (suite *statelessActionsTestSuite) TestStatelessRollbackJobActionSuccess() {413 batchSize := uint32(1)414 maxInstanceRetries := uint32(2)415 maxTolerableInstanceFailures := uint32(1)416 startPaused := true417 inPlace := false418 startPods := false419 opaque := "test"420 entityVersion := "1-1-1"421 suite.statelessClient.EXPECT().422 GetJob(gomock.Any(), gomock.Any()).423 Return(&svc.GetJobResponse{424 JobInfo: &stateless.JobInfo{425 Spec: &stateless.JobSpec{426 Name: "new-job",427 },428 },429 }, nil)430 suite.statelessClient.EXPECT().431 GetJob(gomock.Any(), gomock.Any()).432 Return(&svc.GetJobResponse{433 Summary: &stateless.JobSummary{434 Status: &stateless.JobStatus{435 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},436 },437 },438 }, nil)439 suite.statelessClient.EXPECT().440 ReplaceJob(gomock.Any(), gomock.Any()).441 Return(&svc.ReplaceJobResponse{442 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},443 }, nil)444 suite.NoError(suite.client.StatelessRollbackJobAction(445 testJobID,446 batchSize,447 entityVersion,448 maxInstanceRetries,449 maxTolerableInstanceFailures,450 startPaused,451 opaque,452 inPlace,453 startPods,454 ))455}456// TestStatelessReplaceJobActionLookupResourcePoolIDFail tests the failure case of replace457// job due to look up resource pool fails458func (suite *statelessActionsTestSuite) TestStatelessRollbackJobGetFailure() {459 batchSize := uint32(1)460 maxInstanceRetries := uint32(2)461 maxTolerableInstanceFailures := uint32(1)462 startPaused := true463 inPlace := false464 startPods := false465 opaque := "test"466 entityVersion := "1-1-1"467 suite.statelessClient.EXPECT().468 GetJob(gomock.Any(), gomock.Any()).469 Return(&svc.GetJobResponse{}, yarpcerrors.InternalErrorf("test error"))470 suite.Error(suite.client.StatelessRollbackJobAction(471 testJobID,472 batchSize,473 entityVersion,474 maxInstanceRetries,475 maxTolerableInstanceFailures,476 startPaused,477 opaque,478 inPlace,479 startPods,480 ))481}482// TestStatelessReplaceJobActionGetJobFail tests the failure case of replace483// job due to get job fails484func (suite *statelessActionsTestSuite) TestStatelessRollbackJobGetJobSummaryFail() {485 batchSize := uint32(1)486 maxInstanceRetries := uint32(2)487 maxTolerableInstanceFailures := uint32(1)488 startPaused := true489 inPlace := false490 startPods := false491 opaque := "test"492 entityVersion := "1-1-1"493 suite.statelessClient.EXPECT().494 GetJob(gomock.Any(), gomock.Any()).495 Return(&svc.GetJobResponse{496 JobInfo: &stateless.JobInfo{497 Spec: &stateless.JobSpec{498 Name: "new-job",499 },500 },501 }, nil)502 suite.statelessClient.EXPECT().503 GetJob(gomock.Any(), gomock.Any()).504 Return(&svc.GetJobResponse{}, yarpcerrors.InternalErrorf("test error"))505 suite.Error(suite.client.StatelessRollbackJobAction(506 testJobID,507 batchSize,508 entityVersion,509 maxInstanceRetries,510 maxTolerableInstanceFailures,511 startPaused,512 opaque,513 inPlace,514 startPods,515 ))516}517func (suite *statelessActionsTestSuite) TestStatelessRollbackJobReplaceFailure() {518 batchSize := uint32(1)519 maxInstanceRetries := uint32(2)520 maxTolerableInstanceFailures := uint32(1)521 startPaused := true522 inPlace := false523 startPods := false524 opaque := "test"525 entityVersion := "1-1-1"526 suite.statelessClient.EXPECT().527 GetJob(gomock.Any(), gomock.Any()).528 Return(&svc.GetJobResponse{529 JobInfo: &stateless.JobInfo{530 Spec: &stateless.JobSpec{531 Name: "new-job",532 },533 },534 }, nil)535 suite.statelessClient.EXPECT().536 GetJob(gomock.Any(), gomock.Any()).537 Return(&svc.GetJobResponse{538 Summary: &stateless.JobSummary{539 Status: &stateless.JobStatus{540 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},541 },542 },543 }, nil)544 suite.statelessClient.EXPECT().545 ReplaceJob(gomock.Any(), gomock.Any()).546 Return(&svc.ReplaceJobResponse{}, yarpcerrors.InternalErrorf("test error"))547 suite.Error(suite.client.StatelessRollbackJobAction(548 testJobID,549 batchSize,550 entityVersion,551 maxInstanceRetries,552 maxTolerableInstanceFailures,553 startPaused,554 opaque,555 inPlace,556 startPods,557 ))558}559// TestStatelessListJobsActionSuccess tests executing560// ListJobsAction successfully561func (suite *statelessActionsTestSuite) TestStatelessListJobsActionSuccess() {562 stream := mocks.NewMockJobServiceServiceListJobsYARPCClient(suite.ctrl)563 jobs := &svc.ListJobsResponse{564 Jobs: []*stateless.JobSummary{565 {566 JobId: &v1alphapeloton.JobID{Value: testJobID},567 Name: "test",568 },569 },570 }571 suite.statelessClient.EXPECT().572 ListJobs(gomock.Any(), gomock.Any()).573 Return(stream, nil)574 gomock.InOrder(575 stream.EXPECT().576 Recv().577 Return(jobs, nil),578 stream.EXPECT().579 Recv().580 Return(nil, io.EOF),581 )582 suite.NoError(suite.client.StatelessListJobsAction())583}584// TestStatelessListJobsActionSuccess tests executing585// ListJobsAction and getting an error from the initial connection586func (suite *statelessActionsTestSuite) TestStatelessListJobsActionError() {587 suite.statelessClient.EXPECT().588 ListJobs(gomock.Any(), gomock.Any()).589 Return(nil, yarpcerrors.InternalErrorf("test error"))590 suite.Error(suite.client.StatelessListJobsAction())591}592// TestStatelessListJobsActionSuccess tests executing593// ListJobsAction and getting an error in stream receive594func (suite *statelessActionsTestSuite) TestStatelessListJobsActionRecvError() {595 stream := mocks.NewMockJobServiceServiceListJobsYARPCClient(suite.ctrl)596 suite.statelessClient.EXPECT().597 ListJobs(gomock.Any(), gomock.Any()).598 Return(stream, nil)599 stream.EXPECT().600 Recv().601 Return(nil, yarpcerrors.InternalErrorf("test error"))602 suite.Error(suite.client.StatelessListJobsAction())603}604// TestStatelessCreateJobActionSuccess tests the success case of creating a job605func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionSuccess() {606 gomock.InOrder(607 suite.resClient.EXPECT().608 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{609 Path: &respool.ResourcePoolPath{610 Value: testRespoolPath,611 },612 }).613 Return(&respool.LookupResponse{614 Id: &peloton.ResourcePoolID{Value: suite.respoolID.GetValue()},615 }, nil),616 suite.statelessClient.EXPECT().617 CreateJob(618 gomock.Any(),619 &svc.CreateJobRequest{620 JobId: &v1alphapeloton.JobID{Value: testJobID},621 Spec: suite.getSpec(),622 Secrets: api.ConvertV0SecretsToV1Secrets([]*peloton.Secret{623 jobmgrtask.CreateSecretProto(624 "", testSecretPath, []byte(testSecretStr),625 ),626 }),627 OpaqueData: &v1alphapeloton.OpaqueData{Data: testOpaqueData},628 CreateSpec: &stateless.CreateSpec{629 StartPaused: false,630 BatchSize: 0,631 MaxTolerableInstanceFailures: testMaxTolerableInstanceFailures,632 MaxInstanceRetries: testMaxInstanceRetries,633 },634 },635 ).Return(&svc.CreateJobResponse{636 JobId: &v1alphapeloton.JobID{Value: testJobID},637 Version: &v1alphapeloton.EntityVersion{Value: testEntityVersion},638 }, nil),639 )640 suite.NoError(suite.client.StatelessCreateAction(641 testJobID,642 testRespoolPath,643 0,644 testStatelessSpecConfig,645 testSecretPath,646 []byte(testSecretStr),647 testOpaqueData,648 false,649 testMaxInstanceRetries,650 testMaxTolerableInstanceFailures,651 ))652}653// TestStatelessCreateJobActionLookupResourcePoolIDFailure tests the failure654// case of creating a stateless job due to look up resource pool failure655func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionLookupResourcePoolIDFailure() {656 suite.resClient.EXPECT().657 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{658 Path: &respool.ResourcePoolPath{659 Value: testRespoolPath,660 },661 }).662 Return(nil, yarpcerrors.InternalErrorf("test error"))663 suite.Error(suite.client.StatelessCreateAction(664 testJobID,665 testRespoolPath,666 0,667 testStatelessSpecConfig,668 testSecretPath,669 []byte(testSecretStr),670 testOpaqueData,671 false,672 testMaxInstanceRetries,673 testMaxTolerableInstanceFailures,674 ))675}676// TestStatelessCreateJobActionNilResourcePoolID tests the failure case of677// creating a stateless job due to look up resource pool returns nil respoolID678func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionNilResourcePoolID() {679 suite.resClient.EXPECT().680 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{681 Path: &respool.ResourcePoolPath{682 Value: testRespoolPath,683 },684 }).Return(&respool.LookupResponse{}, nil)685 suite.Error(suite.client.StatelessCreateAction(686 testJobID,687 testRespoolPath,688 0,689 testStatelessSpecConfig,690 testSecretPath,691 []byte(testSecretStr),692 testOpaqueData,693 false,694 testMaxInstanceRetries,695 testMaxTolerableInstanceFailures,696 ))697}698// TestStatelessCreateJobActionJobAlreadyExists tests the failure case of699// creating a job when the jobID already exists700func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionJobAlreadyExists() {701 gomock.InOrder(702 suite.resClient.EXPECT().703 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{704 Path: &respool.ResourcePoolPath{705 Value: testRespoolPath,706 },707 }).708 Return(&respool.LookupResponse{709 Id: &peloton.ResourcePoolID{Value: suite.respoolID.GetValue()},710 }, nil),711 suite.statelessClient.EXPECT().712 CreateJob(713 gomock.Any(),714 &svc.CreateJobRequest{715 JobId: &v1alphapeloton.JobID{Value: testJobID},716 Spec: suite.getSpec(),717 OpaqueData: &v1alphapeloton.OpaqueData{Data: testOpaqueData},718 CreateSpec: &stateless.CreateSpec{719 StartPaused: false,720 BatchSize: 0,721 MaxTolerableInstanceFailures: testMaxTolerableInstanceFailures,722 MaxInstanceRetries: testMaxInstanceRetries,723 },724 },725 ).Return(nil, yarpcerrors.AlreadyExistsErrorf("test error")),726 )727 suite.Error(suite.client.StatelessCreateAction(728 testJobID,729 testRespoolPath,730 0,731 testStatelessSpecConfig,732 "",733 []byte(""),734 testOpaqueData,735 false,736 testMaxInstanceRetries,737 testMaxTolerableInstanceFailures,738 ))739}740// TestStatelessCreateJobActionInvalidSpec tests the failure case of741// creating a job due to invalid spec path742func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionInvalidSpecPath() {743 gomock.InOrder(744 suite.resClient.EXPECT().745 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{746 Path: &respool.ResourcePoolPath{747 Value: testRespoolPath,748 },749 }).750 Return(&respool.LookupResponse{751 Id: &peloton.ResourcePoolID{Value: suite.respoolID.GetValue()},752 }, nil),753 )754 suite.Error(suite.client.StatelessCreateAction(755 testJobID,756 testRespoolPath,757 0,758 "invalid-path",759 "",760 []byte(""),761 testOpaqueData,762 false,763 testMaxInstanceRetries,764 testMaxTolerableInstanceFailures,765 ))766}767// TestStatelessCreateJobActionUnmarshalFailed tests the failure case of768// creating a job due to error while unmarshaling job spec769func (suite *statelessActionsTestSuite) TestStatelessCreateJobActionInvalidSpec() {770 gomock.InOrder(771 suite.resClient.EXPECT().772 LookupResourcePoolID(gomock.Any(), &respool.LookupRequest{773 Path: &respool.ResourcePoolPath{774 Value: testRespoolPath,775 },776 }).777 Return(&respool.LookupResponse{778 Id: &peloton.ResourcePoolID{Value: suite.respoolID.GetValue()},779 }, nil),780 suite.statelessClient.EXPECT().781 CreateJob(782 gomock.Any(),783 &svc.CreateJobRequest{784 JobId: &v1alphapeloton.JobID{Value: testJobID},785 Spec: suite.getSpec(),786 OpaqueData: &v1alphapeloton.OpaqueData{Data: testOpaqueData},787 CreateSpec: &stateless.CreateSpec{788 StartPaused: false,789 BatchSize: 0,790 MaxTolerableInstanceFailures: testMaxTolerableInstanceFailures,791 MaxInstanceRetries: testMaxInstanceRetries,792 },793 },794 ).Return(nil, yarpcerrors.InvalidArgumentErrorf("test error")),795 )796 suite.Error(suite.client.StatelessCreateAction(797 testJobID,798 testRespoolPath,799 0,800 testStatelessSpecConfig,801 "",802 []byte(""),803 testOpaqueData,804 false,805 testMaxInstanceRetries,806 testMaxTolerableInstanceFailures,807 ))808}809func (suite *statelessActionsTestSuite) getSpec() *stateless.JobSpec {810 var jobSpec stateless.JobSpec811 buffer, err := ioutil.ReadFile(testStatelessSpecConfig)812 suite.NoError(err)813 err = yaml.Unmarshal(buffer, &jobSpec)814 suite.NoError(err)815 jobSpec.RespoolId = suite.respoolID816 return &jobSpec817}818// TestStatelessReplaceJobDiffActionSuccess tests successfully invoking819// the GetReplaceJobDiff API820func (suite *statelessActionsTestSuite) TestStatelessReplaceJobDiffActionSuccess() {...

Full Screen

Full Screen

fallback_test.go

Source:fallback_test.go Github

copy

Full Screen

...77 Expect(value).Should(Equal(expectedMetricValue))78 })79 It("should reset the health status when scaler metrics are available", func() {80 expectedMetricValue := int64(6)81 startingNumberOfFailures := int32(5)82 primeGetMetrics(scaler, expectedMetricValue)83 so := buildScaledObject(84 &kedav1alpha1.Fallback{85 FailureThreshold: int32(3),86 Replicas: int32(10),87 },88 &kedav1alpha1.ScaledObjectStatus{89 Health: map[string]kedav1alpha1.HealthStatus{90 metricName: {91 NumberOfFailures: &startingNumberOfFailures,92 Status: kedav1alpha1.HealthStatusFailing,93 },94 },95 },96 )97 metricSpec := createMetricSpec(3)98 expectStatusPatch(ctrl, client)99 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)100 metrics, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)101 Expect(err).ToNot(HaveOccurred())102 value, _ := metrics[0].Value.AsInt64()103 Expect(value).Should(Equal(expectedMetricValue))104 Expect(so.Status.Health[metricName]).To(haveFailureAndStatus(0, kedav1alpha1.HealthStatusHappy))105 })106 It("should propagate the error when fallback is disabled", func() {107 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))108 so := buildScaledObject(nil, nil)109 metricSpec := createMetricSpec(3)110 expectStatusPatch(ctrl, client)111 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)112 _, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)113 Expect(err).ShouldNot(BeNil())114 Expect(err.Error()).Should(Equal("Some error"))115 })116 It("should bump the number of failures when metrics call fails", func() {117 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))118 startingNumberOfFailures := int32(0)119 so := buildScaledObject(120 &kedav1alpha1.Fallback{121 FailureThreshold: int32(3),122 Replicas: int32(10),123 },124 &kedav1alpha1.ScaledObjectStatus{125 Health: map[string]kedav1alpha1.HealthStatus{126 metricName: {127 NumberOfFailures: &startingNumberOfFailures,128 Status: kedav1alpha1.HealthStatusHappy,129 },130 },131 },132 )133 metricSpec := createMetricSpec(10)134 expectStatusPatch(ctrl, client)135 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)136 _, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)137 Expect(err).ShouldNot(BeNil())138 Expect(err.Error()).Should(Equal("Some error"))139 Expect(so.Status.Health[metricName]).To(haveFailureAndStatus(1, kedav1alpha1.HealthStatusFailing))140 })141 It("should return a normalised metric when number of failures are beyond threshold", func() {142 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))143 startingNumberOfFailures := int32(3)144 expectedMetricValue := int64(100)145 so := buildScaledObject(146 &kedav1alpha1.Fallback{147 FailureThreshold: int32(3),148 Replicas: int32(10),149 },150 &kedav1alpha1.ScaledObjectStatus{151 Health: map[string]kedav1alpha1.HealthStatus{152 metricName: {153 NumberOfFailures: &startingNumberOfFailures,154 Status: kedav1alpha1.HealthStatusHappy,155 },156 },157 },158 )159 metricSpec := createMetricSpec(10)160 expectStatusPatch(ctrl, client)161 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)162 metrics, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)163 Expect(err).ToNot(HaveOccurred())164 value, _ := metrics[0].Value.AsInt64()165 Expect(value).Should(Equal(expectedMetricValue))166 Expect(so.Status.Health[metricName]).To(haveFailureAndStatus(4, kedav1alpha1.HealthStatusFailing))167 })168 It("should behave as if fallback is disabled when the metrics spec target type is not average value metric", func() {169 so := buildScaledObject(170 &kedav1alpha1.Fallback{171 FailureThreshold: int32(3),172 Replicas: int32(10),173 }, nil,174 )175 qty := resource.NewQuantity(int64(3), resource.DecimalSI)176 metricsSpec := v2beta2.MetricSpec{177 External: &v2beta2.ExternalMetricSource{178 Target: v2beta2.MetricTarget{179 Type: v2beta2.UtilizationMetricType,180 Value: qty,181 },182 },183 }184 isEnabled := isFallbackEnabled(so, metricsSpec)185 Expect(isEnabled).Should(BeFalse())186 })187 It("should ignore error if we fail to update kubernetes status", func() {188 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))189 startingNumberOfFailures := int32(3)190 expectedMetricValue := int64(100)191 so := buildScaledObject(192 &kedav1alpha1.Fallback{193 FailureThreshold: int32(3),194 Replicas: int32(10),195 },196 &kedav1alpha1.ScaledObjectStatus{197 Health: map[string]kedav1alpha1.HealthStatus{198 metricName: {199 NumberOfFailures: &startingNumberOfFailures,200 Status: kedav1alpha1.HealthStatusHappy,201 },202 },203 },204 )205 metricSpec := createMetricSpec(10)206 statusWriter := mock_client.NewMockStatusWriter(ctrl)207 statusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("Some error"))208 client.EXPECT().Status().Return(statusWriter)209 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)210 metrics, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)211 Expect(err).ToNot(HaveOccurred())212 value, _ := metrics[0].Value.AsInt64()213 Expect(value).Should(Equal(expectedMetricValue))214 Expect(so.Status.Health[metricName]).To(haveFailureAndStatus(4, kedav1alpha1.HealthStatusFailing))215 })216 It("should return error when fallback is enabled but scaledobject has invalid parameter", func() {217 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))218 startingNumberOfFailures := int32(3)219 so := buildScaledObject(220 &kedav1alpha1.Fallback{221 FailureThreshold: int32(-3),222 Replicas: int32(10),223 },224 &kedav1alpha1.ScaledObjectStatus{225 Health: map[string]kedav1alpha1.HealthStatus{226 metricName: {227 NumberOfFailures: &startingNumberOfFailures,228 Status: kedav1alpha1.HealthStatusHappy,229 },230 },231 },232 )233 metricSpec := createMetricSpec(10)234 expectStatusPatch(ctrl, client)235 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)236 _, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)237 Expect(err).ShouldNot(BeNil())238 Expect(err.Error()).Should(Equal("Some error"))239 })240 It("should set the fallback condition when a fallback exists in the scaled object", func() {241 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))242 startingNumberOfFailures := int32(3)243 failingNumberOfFailures := int32(6)244 anotherMetricName := "another metric name"245 so := buildScaledObject(246 &kedav1alpha1.Fallback{247 FailureThreshold: int32(3),248 Replicas: int32(10),249 },250 &kedav1alpha1.ScaledObjectStatus{251 Health: map[string]kedav1alpha1.HealthStatus{252 anotherMetricName: {253 NumberOfFailures: &failingNumberOfFailures,254 Status: kedav1alpha1.HealthStatusFailing,255 },256 metricName: {257 NumberOfFailures: &startingNumberOfFailures,258 Status: kedav1alpha1.HealthStatusHappy,259 },260 },261 },262 )263 metricSpec := createMetricSpec(10)264 expectStatusPatch(ctrl, client)265 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)266 _, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)267 Expect(err).ToNot(HaveOccurred())268 condition := so.Status.Conditions.GetFallbackCondition()269 Expect(condition.IsTrue()).Should(BeTrue())270 })271 It("should set the fallback condition to false if the config is invalid", func() {272 scaler.EXPECT().GetMetrics(gomock.Any(), gomock.Eq(metricName), gomock.Any()).Return(nil, errors.New("Some error"))273 startingNumberOfFailures := int32(3)274 failingNumberOfFailures := int32(6)275 anotherMetricName := "another metric name"276 so := buildScaledObject(277 &kedav1alpha1.Fallback{278 FailureThreshold: int32(-3),279 Replicas: int32(10),280 },281 &kedav1alpha1.ScaledObjectStatus{282 Health: map[string]kedav1alpha1.HealthStatus{283 anotherMetricName: {284 NumberOfFailures: &failingNumberOfFailures,285 Status: kedav1alpha1.HealthStatusFailing,286 },287 metricName: {288 NumberOfFailures: &startingNumberOfFailures,289 Status: kedav1alpha1.HealthStatusHappy,290 },291 },292 },293 )294 metricSpec := createMetricSpec(10)295 expectStatusPatch(ctrl, client)296 metrics, err := scaler.GetMetrics(context.Background(), metricName, nil)297 _, err = providerUnderTest.getMetricsWithFallback(context.Background(), metrics, err, metricName, so, metricSpec)298 Expect(err).ShouldNot(BeNil())299 Expect(err.Error()).Should(Equal("Some error"))300 condition := so.Status.Conditions.GetFallbackCondition()301 Expect(condition.IsTrue()).Should(BeFalse())302 })303})304func haveFailureAndStatus(numberOfFailures int, status kedav1alpha1.HealthStatusType) types.GomegaMatcher {305 return &healthStatusMatcher{numberOfFailures: numberOfFailures, status: status}306}307type healthStatusMatcher struct {308 numberOfFailures int309 status kedav1alpha1.HealthStatusType310}311func (h *healthStatusMatcher) Match(actual interface{}) (success bool, err error) {312 switch v := actual.(type) {313 case kedav1alpha1.HealthStatus:314 return *v.NumberOfFailures == int32(h.numberOfFailures) && v.Status == h.status, nil315 default:316 return false, fmt.Errorf("expected kedav1alpha1.HealthStatus, got %v", actual)317 }318}319func (h *healthStatusMatcher) FailureMessage(actual interface{}) (message string) {320 switch v := actual.(type) {321 case kedav1alpha1.HealthStatus:322 return fmt.Sprintf("expected HealthStatus with NumberOfFailures %d and Status %s, but got NumberOfFailures %d and Status %s", h.numberOfFailures, h.status, *v.NumberOfFailures, v.Status)323 default:324 return "unexpected error"325 }326}327func (h *healthStatusMatcher) NegatedFailureMessage(actual interface{}) (message string) {328 switch v := actual.(type) {329 case kedav1alpha1.HealthStatus:330 return fmt.Sprintf("did not expect HealthStatus with NumberOfFailures %d and Status %s, but got NumberOfFailures %d and Status %s", h.numberOfFailures, h.status, *v.NumberOfFailures, v.Status)331 default:332 return "unexpected error"333 }334}335func expectStatusPatch(ctrl *gomock.Controller, client *mock_client.MockClient) {336 statusWriter := mock_client.NewMockStatusWriter(ctrl)337 statusWriter.EXPECT().Patch(gomock.Any(), gomock.Any(), gomock.Any())338 client.EXPECT().Status().Return(statusWriter)339}340func buildScaledObject(fallbackConfig *kedav1alpha1.Fallback, status *kedav1alpha1.ScaledObjectStatus) *kedav1alpha1.ScaledObject {341 scaledObject := &kedav1alpha1.ScaledObject{342 ObjectMeta: metav1.ObjectMeta{Name: "clean-up-test", Namespace: "default"},343 Spec: kedav1alpha1.ScaledObjectSpec{344 ScaleTargetRef: &kedav1alpha1.ScaleTarget{...

Full Screen

Full Screen

mock_datastore_test.go

Source:mock_datastore_test.go Github

copy

Full Screen

...215 Return(result, errors.New("my-error"))216 err = suite.store.deleteJobConfigVersion(ctx, suite.testJobID, 0)217 suite.Error(err)218}219// TestWorkflowEventsFailures tests failure scenarios for workflow events220func (suite *MockDatastoreTestSuite) TestWorkflowEventsFailures() {221 updateID := &peloton.UpdateID{222 Value: testUpdateID,223 }224 err := suite.store.AddWorkflowEvent(225 context.Background(),226 updateID,227 0,228 models.WorkflowType_UPDATE,229 update.State_ROLLING_FORWARD)230 suite.Error(err)231 err = suite.store.deleteWorkflowEvents(context.Background(), updateID, 0)232 suite.Error(err)233 _, err = suite.store.GetWorkflowEvents(context.Background(), updateID, 0, 0)234 suite.Error(err)...

Full Screen

Full Screen

indicator_test.go

Source:indicator_test.go Github

copy

Full Screen

1package service2import (3 "elb2c/gh-action/api/checkrun"4 "elb2c/gh-action/config"5 "errors"6 "testing"7 "github.com/golang/mock/gomock"8 "github.com/stretchr/testify/assert"9)10func Test_passing_test_failure_report_returns_no_error_and_creates_and_updates_an_check_run(test *testing.T) {11 mockCtl := gomock.NewController(test)12 defer mockCtl.Finish()13 cfg := config.Config{14 TestResultFile: "test_report.xml",15 }16 parserMock := NewMockTestResultParser(mockCtl)17 creatorMock := checkrun.NewMockCreator(mockCtl)18 updaterMock := checkrun.NewMockUpdater(mockCtl)19 svc := NewTestFailureAnnotator(&cfg, parserMock, creatorMock, updaterMock)20 checkID := 121 creatorMock.EXPECT().Create().Return(checkID, nil)22 var failures []TestFailure23 failures = append(failures, TestFailure{24 Line: 1,25 File: "error_test.go",26 Name: "Test_passing_an_error_returns_an_error",27 Reason: "Because of errors",28 })29 failures = append(failures, TestFailure{30 Line: 10,31 File: "blender_test.go",32 Name: "Test_passing_an_apple_returns_an_apple_juice",33 Reason: "Because of blender",34 })35 parserMock.EXPECT().Parse(gomock.Any()).Return(failures, nil)36 var annotations []checkrun.Annotation37 annotations = append(annotations, checkrun.Annotation{38 Title: "Test_passing_an_error_returns_an_error",39 Path: "error_test.go",40 StartLine: 1,41 EndLine: 1,42 Level: "failure",43 Message: "Because of errors",44 })45 annotations = append(annotations, checkrun.Annotation{46 Title: "Test_passing_an_apple_returns_an_apple_juice",47 Path: "blender_test.go",48 StartLine: 10,49 EndLine: 10,50 Level: "failure",51 Message: "Because of blender",52 })53 updaterMock.EXPECT().Update(checkID, annotations).Return(nil)54 err := svc.Annotate()55 assert.NoError(test, err)56}57func Test_passing_no_test_failure_report_returns_no_error_and_creates_and_updates_an_check_run(test *testing.T) {58 mockCtl := gomock.NewController(test)59 defer mockCtl.Finish()60 cfg := config.Config{61 TestResultFile: "test_report.xml",62 }63 parserMock := NewMockTestResultParser(mockCtl)64 creatorMock := checkrun.NewMockCreator(mockCtl)65 updaterMock := checkrun.NewMockUpdater(mockCtl)66 svc := NewTestFailureAnnotator(&cfg, parserMock, creatorMock, updaterMock)67 checkID := 168 creatorMock.EXPECT().Create().Return(checkID, nil)69 var failures []TestFailure70 parserMock.EXPECT().Parse(gomock.Any()).Return(failures, nil)71 emptyAnnotations := make([]checkrun.Annotation, 0)72 updaterMock.EXPECT().Update(checkID, emptyAnnotations).Return(nil)73 err := svc.Annotate()74 assert.NoError(test, err)75}76func Test_missing_test_report_config_returns_an_error(test *testing.T) {77 mockCtl := gomock.NewController(test)78 defer mockCtl.Finish()79 parserMock := NewMockTestResultParser(mockCtl)80 creatorMock := checkrun.NewMockCreator(mockCtl)81 updaterMock := checkrun.NewMockUpdater(mockCtl)82 svc := NewTestFailureAnnotator(nil, parserMock, creatorMock, updaterMock)83 err := svc.Annotate()84 assert.Error(test, err)85 creatorMock.EXPECT().Create().Times(0)86 parserMock.EXPECT().Parse(gomock.Any()).Times(0)87 updaterMock.EXPECT().Update(gomock.Any(), gomock.Any()).Times(0)88}89func Test_assuming_failed_to_parse_test_report_returns_no_error(test *testing.T) {90 mockCtl := gomock.NewController(test)91 defer mockCtl.Finish()92 cfg := config.Config{93 TestResultFile: "test_report.xml",94 }95 parserMock := NewMockTestResultParser(mockCtl)96 creatorMock := checkrun.NewMockCreator(mockCtl)97 updaterMock := checkrun.NewMockUpdater(mockCtl)98 svc := NewTestFailureAnnotator(&cfg, parserMock, creatorMock, updaterMock)99 checkID := 1100 creatorMock.EXPECT().Create().Return(checkID, nil)101 parseFailed := errors.New("Failed to parse the test report")102 parserMock.EXPECT().Parse(gomock.Any()).Return(nil, parseFailed)103 emptyAnnotations := make([]checkrun.Annotation, 0)104 updaterMock.EXPECT().Update(checkID, emptyAnnotations).Return(nil)105 err := svc.Annotate()106 assert.NoError(test, err)107}108func Test_assuming_failed_to_create_a_check_run_returns_an_error(test *testing.T) {109 mockCtl := gomock.NewController(test)110 defer mockCtl.Finish()111 cfg := config.Config{112 TestResultFile: "test_report.xml",113 }114 parserMock := NewMockTestResultParser(mockCtl)115 creatorMock := checkrun.NewMockCreator(mockCtl)116 updaterMock := checkrun.NewMockUpdater(mockCtl)117 svc := NewTestFailureAnnotator(&cfg, parserMock, creatorMock, updaterMock)118 createFailed := errors.New("Failed to create a check run")119 creatorMock.EXPECT().Create().Return(0, createFailed)120 err := svc.Annotate()121 assert.Error(test, err)122 parserMock.EXPECT().Parse(gomock.Any()).Times(0)123 updaterMock.EXPECT().Update(gomock.Any(), gomock.Any()).Times(0)124}125func Test_assuming_failed_to_update_a_check_run_returns_an_error(test *testing.T) {126 mockCtl := gomock.NewController(test)127 defer mockCtl.Finish()128 cfg := config.Config{129 TestResultFile: "test_report.xml",130 }131 parserMock := NewMockTestResultParser(mockCtl)132 creatorMock := checkrun.NewMockCreator(mockCtl)133 updaterMock := checkrun.NewMockUpdater(mockCtl)134 svc := NewTestFailureAnnotator(&cfg, parserMock, creatorMock, updaterMock)135 checkID := 1136 creatorMock.EXPECT().Create().Return(checkID, nil)137 var failures []TestFailure138 failures = append(failures, TestFailure{139 Line: 1,140 File: "error_test.go",141 Name: "Test_passing_an_error_returns_an_error",142 Reason: "Because of errors",143 })144 parserMock.EXPECT().Parse(gomock.Any()).Return(failures, nil)145 updateFailed := errors.New("Failed to update a check run")146 updaterMock.EXPECT().Update(checkID, gomock.Any()).Return(updateFailed)147 err := svc.Annotate()148 assert.Error(test, err)149}...

Full Screen

Full Screen

Failures

Using AI Code Generation

copy

Full Screen

1import (2func TestMock(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mock := NewMockMyInterface(ctrl)6 mock.EXPECT().MyFunc().Return(1)7 fmt.Println(mock.MyFunc())8 fmt.Println(mock.Failures())9}10 *MyInterface.MyFunc()

Full Screen

Full Screen

Failures

Using AI Code Generation

copy

Full Screen

1func (m *MockMyClass) Failures() []string {2 m.ctrl.T.Helper()3 ret := m.ctrl.Call(m, "Failures")4 ret0, _ := ret[0].([]string)5}6func (m *MockMyClass) Failures() []string {7 m.ctrl.T.Helper()8 ret := m.ctrl.Call(m, "Failures")9 ret0, _ := ret[0].([]string)10}11func (m *MockMyClass) Failures() []string {12 m.ctrl.T.Helper()13 ret := m.ctrl.Call(m, "Failures")14 ret0, _ := ret[0].([]string)15}16func (m *MockMyClass) Failures() []string {17 m.ctrl.T.Helper()18 ret := m.ctrl.Call(m, "Failures")19 ret0, _ := ret[0].([]string)20}21func (m *MockMyClass) Failures() []string {22 m.ctrl.T.Helper()23 ret := m.ctrl.Call(m, "Failures")24 ret0, _ := ret[0].([]string)25}26func (m *MockMyClass) Failures() []string {27 m.ctrl.T.Helper()28 ret := m.ctrl.Call(m, "Failures")29 ret0, _ := ret[0].([]string)30}31func (m *Mock

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful