MCPcopy Create free account
hub / github.com/cloudbase/garm / TestOrgWatcher

Method TestOrgWatcher

database/watcher/watcher_store_test.go:720–785  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

718}
719
720func (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{

Callers

nothing calls this directly

Calls 11

RegisterConsumerFunction · 0.92
WithEntityTypeFilterFunction · 0.92
WithAnyFunction · 0.92
WithOperationTypeFilterFunction · 0.92
consumeEventsFunction · 0.85
CloseMethod · 0.65
CreateOrganizationMethod · 0.65
WatchMethod · 0.65
UpdateOrganizationMethod · 0.65
DeleteOrganizationMethod · 0.65

Tested by

no test coverage detected