()
| 36 | } |
| 37 | |
| 38 | func (s *WatcherStoreTestSuite) TestJobWatcher() { |
| 39 | consumer, err := watcher.RegisterConsumer( |
| 40 | s.ctx, "job-test", |
| 41 | watcher.WithEntityTypeFilter(common.JobEntityType), |
| 42 | watcher.WithAny( |
| 43 | watcher.WithOperationTypeFilter(common.CreateOperation), |
| 44 | watcher.WithOperationTypeFilter(common.UpdateOperation), |
| 45 | watcher.WithOperationTypeFilter(common.DeleteOperation)), |
| 46 | ) |
| 47 | s.Require().NoError(err) |
| 48 | s.Require().NotNil(consumer) |
| 49 | s.T().Cleanup(func() { consumer.Close() }) |
| 50 | consumeEvents(consumer) |
| 51 | |
| 52 | jobParams := params.Job{ |
| 53 | WorkflowJobID: 2, |
| 54 | RunID: 2, |
| 55 | Action: "test-action", |
| 56 | Conclusion: "started", |
| 57 | Status: "in_progress", |
| 58 | Name: "test-job", |
| 59 | } |
| 60 | |
| 61 | job, err := s.store.CreateOrUpdateJob(s.ctx, jobParams) |
| 62 | s.Require().NoError(err) |
| 63 | |
| 64 | select { |
| 65 | case event := <-consumer.Watch(): |
| 66 | s.Require().Equal(common.ChangePayload{ |
| 67 | EntityType: common.JobEntityType, |
| 68 | Operation: common.CreateOperation, |
| 69 | Payload: job, |
| 70 | }, event) |
| 71 | asJob, ok := event.Payload.(params.Job) |
| 72 | s.Require().True(ok) |
| 73 | s.Require().Equal(job.ID, int64(1)) |
| 74 | s.Require().Equal(asJob.ID, int64(1)) |
| 75 | case <-time.After(1 * time.Second): |
| 76 | s.T().Fatal("expected payload not received") |
| 77 | } |
| 78 | |
| 79 | job.Conclusion = "success" |
| 80 | updatedJob, err := s.store.CreateOrUpdateJob(s.ctx, job) |
| 81 | s.Require().NoError(err) |
| 82 | |
| 83 | select { |
| 84 | case event := <-consumer.Watch(): |
| 85 | s.Require().Equal(common.ChangePayload{ |
| 86 | EntityType: common.JobEntityType, |
| 87 | Operation: common.UpdateOperation, |
| 88 | Payload: updatedJob, |
| 89 | }, event) |
| 90 | case <-time.After(1 * time.Second): |
| 91 | s.T().Fatal("expected payload not received") |
| 92 | } |
| 93 | |
| 94 | entityID, err := uuid.NewUUID() |
| 95 | s.Require().NoError(err) |
nothing calls this directly
no test coverage detected