@@ -812,6 +812,91 @@ var _ = Describe("Glance controller", func() {
812812 })
813813 })
814814
815+ When ("Glance is created with RabbitMQ user and vhost" , func () {
816+ BeforeEach (func () {
817+ DeferCleanup (k8sClient .Delete , ctx , CreateGlanceMessageBusSecret (glanceTest .Instance .Namespace , glanceTest .RabbitmqSecretName ))
818+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (namespace , glanceTest .MemcachedInstance , memcachedSpec ))
819+ infra .SimulateMemcachedReady (glanceTest .GlanceMemcached )
820+ spec := GetGlanceDefaultSpec ()
821+ spec ["notificationBusInstance" ] = glanceTest .NotificationsBusInstance
822+ spec ["notificationsBus" ] = map [string ]interface {}{
823+ "user" : "glance-user" ,
824+ "vhost" : "glance-vhost" ,
825+ }
826+ DeferCleanup (th .DeleteInstance , CreateGlance (glanceTest .Instance , spec ))
827+ })
828+ It ("sets custom RabbitMQ user and vhost in TransportURL" , func () {
829+ Eventually (func (g Gomega ) {
830+ transportURL := infra .GetTransportURL (glanceTest .GlanceTransportURL )
831+ g .Expect (transportURL .Spec .Username ).To (Equal ("glance-user" ))
832+ g .Expect (transportURL .Spec .Vhost ).To (Equal ("glance-vhost" ))
833+ }, timeout , interval ).Should (Succeed ())
834+ })
835+ })
836+
837+ When ("Glance is created without custom RabbitMQ config" , func () {
838+ BeforeEach (func () {
839+ DeferCleanup (k8sClient .Delete , ctx , CreateGlanceMessageBusSecret (glanceTest .Instance .Namespace , glanceTest .RabbitmqSecretName ))
840+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (namespace , glanceTest .MemcachedInstance , memcachedSpec ))
841+ infra .SimulateMemcachedReady (glanceTest .GlanceMemcached )
842+ spec := GetGlanceDefaultSpec ()
843+ spec ["notificationBusInstance" ] = glanceTest .NotificationsBusInstance
844+ DeferCleanup (th .DeleteInstance , CreateGlance (glanceTest .Instance , spec ))
845+ })
846+ It ("uses default RabbitMQ configuration in TransportURL" , func () {
847+ Eventually (func (g Gomega ) {
848+ transportURL := infra .GetTransportURL (glanceTest .GlanceTransportURL )
849+ g .Expect (transportURL .Spec .Username ).To (BeEmpty ())
850+ g .Expect (transportURL .Spec .Vhost ).To (BeEmpty ())
851+ }, timeout , interval ).Should (Succeed ())
852+ })
853+ })
854+
855+ When ("Glance starts with notifications enabled and then disables them" , func () {
856+ BeforeEach (func () {
857+ DeferCleanup (k8sClient .Delete , ctx , CreateGlanceMessageBusSecret (glanceTest .Instance .Namespace , glanceTest .RabbitmqSecretName ))
858+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (namespace , glanceTest .MemcachedInstance , memcachedSpec ))
859+ infra .SimulateMemcachedReady (glanceTest .GlanceMemcached )
860+ spec := GetGlanceDefaultSpec ()
861+ spec ["notificationBusInstance" ] = glanceTest .NotificationsBusInstance
862+ spec ["notificationsBus" ] = map [string ]interface {}{
863+ "user" : "glance-notifications" ,
864+ "vhost" : "glance-notifications-vhost" ,
865+ }
866+ DeferCleanup (th .DeleteInstance , CreateGlance (glanceTest .Instance , spec ))
867+ infra .SimulateTransportURLReady (glanceTest .GlanceTransportURL )
868+ })
869+
870+ It ("should initially have notifications enabled" , func () {
871+ Eventually (func (g Gomega ) {
872+ glance := GetGlance (glanceTest .Instance )
873+ g .Expect (glance .Status .NotificationBusSecret ).ToNot (BeEmpty ())
874+ }, timeout , interval ).Should (Succeed ())
875+ })
876+
877+ It ("should disable notifications when notificationBusInstance and notificationsBus are removed" , func () {
878+ // Verify notifications are initially enabled
879+ Eventually (func (g Gomega ) {
880+ glance := GetGlance (glanceTest .Instance )
881+ g .Expect (glance .Status .NotificationBusSecret ).ToNot (BeEmpty ())
882+ }, timeout , interval ).Should (Succeed ())
883+
884+ // Update the Glance spec to remove notifications
885+ Eventually (func (g Gomega ) {
886+ glance := GetGlance (glanceTest .Instance )
887+ glance .Spec .NotificationBusInstance = nil
888+ glance .Spec .NotificationsBus = nil
889+ g .Expect (k8sClient .Update (ctx , glance )).To (Succeed ())
890+ }, timeout , interval ).Should (Succeed ())
891+
892+ // Wait for notifications to be disabled
893+ Eventually (func (g Gomega ) {
894+ glance := GetGlance (glanceTest .Instance )
895+ g .Expect (glance .Status .NotificationBusSecret ).To (BeEmpty ())
896+ }, timeout , interval ).Should (Succeed ())
897+ })
898+ })
899+
815900 // Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests
816901 // that exercise standard account create / update patterns that should be
817902 // common to all controllers that ensure MariaDBAccount CRs.
0 commit comments