()
| 718 | } |
| 719 | |
| 720 | func (s *WatcherStoreTestSuite) TestOrgWatcher() { |
| 721 | consumer, err := watcher.RegisterConsumer( |
| 722 | s.ctx, "org-test", |
| 723 | watcher.WithEntityTypeFilter(common.OrganizationEntityType), |
| 724 | watcher.WithAny( |
| 725 | watcher.WithOperationTypeFilter(common.CreateOperation), |
| 726 | watcher.WithOperationTypeFilter(common.UpdateOperation), |
| 727 | watcher.WithOperationTypeFilter(common.DeleteOperation)), |
| 728 | ) |
| 729 | s.Require().NoError(err) |
| 730 | s.Require().NotNil(consumer) |
| 731 | s.T().Cleanup(func() { consumer.Close() }) |
| 732 | consumeEvents(consumer) |
| 733 | |
| 734 | ep := garmTesting.CreateDefaultGithubEndpoint(s.ctx, s.store, s.T()) |
| 735 | creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep) |
| 736 | s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) }) |
| 737 | |
| 738 | org, err := s.store.CreateOrganization(s.ctx, "test-org", creds, "test-secret", params.PoolBalancerTypeRoundRobin, false) |
| 739 | s.Require().NoError(err) |
| 740 | s.Require().NotEmpty(org.ID) |
| 741 | |
| 742 | select { |
| 743 | case event := <-consumer.Watch(): |
| 744 | s.Require().Equal(common.ChangePayload{ |
| 745 | EntityType: common.OrganizationEntityType, |
| 746 | Operation: common.CreateOperation, |
| 747 | Payload: org, |
| 748 | }, event) |
| 749 | case <-time.After(1 * time.Second): |
| 750 | s.T().Fatal("expected payload not received") |
| 751 | } |
| 752 | |
| 753 | updateParams := params.UpdateEntityParams{ |
| 754 | WebhookSecret: "updated", |
| 755 | } |
| 756 | |
| 757 | updatedOrg, err := s.store.UpdateOrganization(s.ctx, org.ID, updateParams) |
| 758 | s.Require().NoError(err) |
| 759 | s.Require().Equal("updated", updatedOrg.WebhookSecret) |
| 760 | |
| 761 | select { |
| 762 | case event := <-consumer.Watch(): |
| 763 | s.Require().Equal(common.ChangePayload{ |
| 764 | EntityType: common.OrganizationEntityType, |
| 765 | Operation: common.UpdateOperation, |
| 766 | Payload: updatedOrg, |
| 767 | }, event) |
| 768 | case <-time.After(1 * time.Second): |
| 769 | s.T().Fatal("expected payload not received") |
| 770 | } |
| 771 | |
| 772 | err = s.store.DeleteOrganization(s.ctx, org.ID) |
| 773 | s.Require().NoError(err) |
| 774 | |
| 775 | select { |
| 776 | case event := <-consumer.Watch(): |
| 777 | s.Require().Equal(common.ChangePayload{ |
nothing calls this directly
no test coverage detected