@@ -29,6 +29,7 @@ var _ = Describe("ParseReference", func() {
29
29
existingService * corev1.Service
30
30
ctx = context .Background ()
31
31
namespace = "rabbitmq-system"
32
+ uriAnnotationKey = "rabbitmq.com/operator-connection-uri"
32
33
)
33
34
34
35
JustBeforeEach (func () {
@@ -765,6 +766,159 @@ var _ = Describe("ParseReference", func() {
765
766
})
766
767
767
768
})
769
+
770
+ When ("the RabbitmqCluster is annotated with connection uri override" , func () {
771
+ BeforeEach (func () {
772
+ existingRabbitMQCluster = & rabbitmqv1beta1.RabbitmqCluster {
773
+ ObjectMeta : metav1.ObjectMeta {
774
+ Name : "rmq" ,
775
+ Namespace : namespace ,
776
+ Annotations : map [string ]string {
777
+ uriAnnotationKey : "http://a-rabbitmq-test:2333" ,
778
+ },
779
+ },
780
+ Status : rabbitmqv1beta1.RabbitmqClusterStatus {
781
+ Binding : & corev1.LocalObjectReference {
782
+ Name : "rmq-default-user-credentials" ,
783
+ },
784
+ DefaultUser : & rabbitmqv1beta1.RabbitmqClusterDefaultUser {
785
+ ServiceReference : & rabbitmqv1beta1.RabbitmqClusterServiceReference {
786
+ Name : "rmq" ,
787
+ Namespace : namespace ,
788
+ },
789
+ },
790
+ },
791
+ }
792
+ existingCredentialSecret = & corev1.Secret {
793
+ ObjectMeta : metav1.ObjectMeta {
794
+ Name : "rmq-default-user-credentials" ,
795
+ Namespace : namespace ,
796
+ },
797
+ Data : map [string ][]byte {
798
+ "username" : []byte (existingRabbitMQUsername ),
799
+ "password" : []byte (existingRabbitMQPassword ),
800
+ },
801
+ }
802
+ existingService = & corev1.Service {
803
+ ObjectMeta : metav1.ObjectMeta {
804
+ Name : "rmq" ,
805
+ Namespace : namespace ,
806
+ },
807
+ Spec : corev1.ServiceSpec {
808
+ ClusterIP : "1.2.3.4" ,
809
+ Ports : []corev1.ServicePort {
810
+ {
811
+ Name : "management" ,
812
+ Port : int32 (15672 ),
813
+ },
814
+ },
815
+ },
816
+ }
817
+ objs = []runtime.Object {existingRabbitMQCluster , existingCredentialSecret , existingService }
818
+ })
819
+
820
+ It ("returns correct credentials" , func () {
821
+ creds , tlsOn , err := rabbitmqclient .ParseReference (ctx , fakeClient ,
822
+ topology.RabbitmqClusterReference {Name : existingRabbitMQCluster .Name },
823
+ existingRabbitMQCluster .Namespace ,
824
+ "" ,
825
+ false )
826
+ Expect (err ).NotTo (HaveOccurred ())
827
+ Expect (tlsOn ).To (BeFalse ())
828
+
829
+ usernameBytes , _ := creds ["username" ]
830
+ passwordBytes , _ := creds ["password" ]
831
+ uriBytes , _ := creds ["uri" ]
832
+ Expect (usernameBytes ).To (Equal (existingRabbitMQUsername ))
833
+ Expect (passwordBytes ).To (Equal (existingRabbitMQPassword ))
834
+ Expect (uriBytes ).To (Equal ("http://a-rabbitmq-test:2333" ))
835
+ })
836
+
837
+ When ("annotated URI has no scheme" , func () {
838
+ BeforeEach (func () {
839
+ * existingRabbitMQCluster = rabbitmqv1beta1.RabbitmqCluster {
840
+ ObjectMeta : metav1.ObjectMeta {
841
+ Name : "rmq" ,
842
+ Namespace : namespace ,
843
+ Annotations : map [string ]string {
844
+ uriAnnotationKey : "a-rabbitmq-test:7890" ,
845
+ },
846
+ },
847
+ Status : rabbitmqv1beta1.RabbitmqClusterStatus {
848
+ Binding : & corev1.LocalObjectReference {
849
+ Name : "rmq-default-user-credentials" ,
850
+ },
851
+ DefaultUser : & rabbitmqv1beta1.RabbitmqClusterDefaultUser {
852
+ ServiceReference : & rabbitmqv1beta1.RabbitmqClusterServiceReference {
853
+ Name : "rmq" ,
854
+ Namespace : namespace ,
855
+ },
856
+ },
857
+ },
858
+ }
859
+ })
860
+
861
+ It ("sets http as the scheme" , func () {
862
+ creds , tlsOn , err := rabbitmqclient .ParseReference (ctx , fakeClient ,
863
+ topology.RabbitmqClusterReference {Name : existingRabbitMQCluster .Name },
864
+ existingRabbitMQCluster .Namespace ,
865
+ "" ,
866
+ false )
867
+ Expect (err ).NotTo (HaveOccurred ())
868
+ Expect (tlsOn ).To (BeFalse ())
869
+
870
+ usernameBytes , _ := creds ["username" ]
871
+ passwordBytes , _ := creds ["password" ]
872
+ uriBytes , _ := creds ["uri" ]
873
+ Expect (usernameBytes ).To (Equal (existingRabbitMQUsername ))
874
+ Expect (passwordBytes ).To (Equal (existingRabbitMQPassword ))
875
+ Expect (uriBytes ).To (Equal ("http://a-rabbitmq-test:7890" ))
876
+ })
877
+ })
878
+
879
+ When ("annotated URI has https as scheme" , func () {
880
+ BeforeEach (func () {
881
+ * existingRabbitMQCluster = rabbitmqv1beta1.RabbitmqCluster {
882
+ ObjectMeta : metav1.ObjectMeta {
883
+ Name : "rmq" ,
884
+ Namespace : namespace ,
885
+ Annotations : map [string ]string {
886
+ uriAnnotationKey : "https://a-rabbitmq-test:2333" ,
887
+ },
888
+ },
889
+ Status : rabbitmqv1beta1.RabbitmqClusterStatus {
890
+ Binding : & corev1.LocalObjectReference {
891
+ Name : "rmq-default-user-credentials" ,
892
+ },
893
+ DefaultUser : & rabbitmqv1beta1.RabbitmqClusterDefaultUser {
894
+ ServiceReference : & rabbitmqv1beta1.RabbitmqClusterServiceReference {
895
+ Name : "rmq" ,
896
+ Namespace : namespace ,
897
+ },
898
+ },
899
+ },
900
+ }
901
+ })
902
+
903
+ It ("returns correct credentials" , func () {
904
+ creds , tlsOn , err := rabbitmqclient .ParseReference (ctx , fakeClient ,
905
+ topology.RabbitmqClusterReference {Name : existingRabbitMQCluster .Name },
906
+ existingRabbitMQCluster .Namespace ,
907
+ "" ,
908
+ false )
909
+ Expect (err ).NotTo (HaveOccurred ())
910
+ Expect (tlsOn ).To (BeTrue ())
911
+
912
+ usernameBytes , _ := creds ["username" ]
913
+ passwordBytes , _ := creds ["password" ]
914
+ uriBytes , _ := creds ["uri" ]
915
+ Expect (usernameBytes ).To (Equal (existingRabbitMQUsername ))
916
+ Expect (passwordBytes ).To (Equal (existingRabbitMQPassword ))
917
+ Expect (uriBytes ).To (Equal ("https://a-rabbitmq-test:2333" ))
918
+ })
919
+ })
920
+
921
+ })
768
922
})
769
923
770
924
var _ = Describe ("AllowedNamespace" , func () {
0 commit comments