@@ -804,32 +804,183 @@ var _ = Describe("[api] FoundationDBCluster", func() {
804
804
},
805
805
}
806
806
807
- coordinatorsStr := []string {
807
+ coordinatorsList := []string {
808
808
"127.0.0.1:4500" ,
809
809
"127.0.0.2:4500" ,
810
810
"127.0.0.3:4500" ,
811
811
}
812
812
813
813
When ("parsing the connection string" , func () {
814
- It ("should be parsed correctly" , func () {
815
- str ,
err := ParseConnectionString (
"test:[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500" )
816
- Expect (err ).NotTo (HaveOccurred ())
817
- Expect (str .DatabaseName ).To (Equal ("test" ))
818
- Expect (str .GenerationID ).To (Equal ("abcd" ))
819
- Expect (str .Coordinators ).To (Equal (coordinatorsStr ))
814
+ var str ConnectionString
815
+ var err error
816
+ var input string
820
817
821
- str , err = ParseConnectionString ("test:abcd" )
822
- Expect (err ).To (HaveOccurred ())
823
- Expect (err .Error ()).To (Equal ("invalid connection string test:abcd" ))
818
+ JustBeforeEach (func () {
819
+ str , err = ParseConnectionString (input )
820
+ })
821
+
822
+ When ("the input is valid" , func () {
823
+ BeforeEach (func () {
824
+ input = "test:[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500"
825
+ })
826
+
827
+ It ("should be parsed correctly" , func () {
828
+ Expect (err ).NotTo (HaveOccurred ())
829
+ Expect (str .DatabaseName ).To (Equal ("test" ))
830
+ Expect (str .GenerationID ).To (Equal ("abcd" ))
831
+ Expect (str .Coordinators ).To (ConsistOf (coordinatorsList ))
832
+ })
833
+ })
834
+
835
+ When ("the input is invalid" , func () {
836
+ BeforeEach (func () {
837
+ input = "test:abcd"
838
+ })
839
+
840
+ It ("should return an error" , func () {
841
+ Expect (err ).To (MatchError (Equal ("invalid connection string: test:abcd, could not split string to get generation ID" )))
842
+ })
843
+ })
844
+
845
+ When ("the input has an invalid char" , func () {
846
+ BeforeEach (func () {
847
+ input = "te-st:abcd"
848
+ })
849
+
850
+ It ("should return an error" , func () {
851
+ Expect (err ).To (MatchError (Equal ("invalid connection string: te-st:abcd, database description can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores" )))
852
+ })
853
+ })
854
+
855
+ When ("the input has an empty description" , func () {
856
+ BeforeEach (func () {
857
+ input = ":[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500"
858
+ })
859
+
860
+ It ("should return an error" , func () {
861
+ Expect (
err ).
To (
MatchError (
Equal (
"invalid connection string: :[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500, database description can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores" )))
862
+ })
863
+ })
864
+
865
+ When ("the input has an empty generation ID" , func () {
866
+ BeforeEach (func () {
867
+ input = "test:@127.0.0.1:4500,127.0.0.2:4500,127.0.0.3:4500"
868
+ })
869
+
870
+ It ("should return an error" , func () {
871
+ Expect (err ).To (MatchError (Equal ("invalid connection string: test:@127.0.0.1:4500,127.0.0.2:4500,127.0.0.3:4500, generation ID can only contain alphanumeric characters (a-z, A-Z, 0-9)" )))
872
+ })
873
+ })
874
+
875
+ When ("the input has no coordinators" , func () {
876
+ BeforeEach (func () {
877
+ input = "test:abcd@"
878
+ })
879
+
880
+ It ("should return an error" , func () {
881
+ Expect (err ).To (MatchError (Equal ("invalid connection string: test:abcd@, could not parse coordinator address: <nil>, got error: cannot parse empty address" )))
882
+ })
883
+ })
884
+
885
+ When ("the input is valid with a single char description" , func () {
886
+ BeforeEach (func () {
887
+ input = "s:[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500"
888
+ })
889
+
890
+ It ("should be parsed correctly" , func () {
891
+ Expect (err ).NotTo (HaveOccurred ())
892
+ Expect (str .DatabaseName ).To (Equal ("s" ))
893
+ Expect (str .GenerationID ).To (Equal ("abcd" ))
894
+ Expect (str .Coordinators ).To (ConsistOf (coordinatorsList ))
895
+ })
896
+ })
897
+
898
+ When ("the input is valid with multiple underscores" , func () {
899
+ BeforeEach (func () {
900
+ input = "fdb_cluster_52v1bpr8:[email protected] :4500:tls,100.82.71.5:4500:tls,100.82.119.151:4500:tls,100.82.122.125:4500:tls,100.82.76.240:4500:tls"
901
+ })
902
+
903
+ It ("should be parsed correctly" , func () {
904
+ Expect (err ).NotTo (HaveOccurred ())
905
+ Expect (str .DatabaseName ).To (Equal ("fdb_cluster_52v1bpr8" ))
906
+ Expect (str .GenerationID ).To (Equal ("rhUbBjrtyweZBQO1U3Td81zyP9d46yEh" ))
907
+ Expect (str .Coordinators ).To (ConsistOf ([]string {
908
+ "100.82.81.253:4500:tls" ,
909
+ "100.82.71.5:4500:tls" ,
910
+ "100.82.119.151:4500:tls" ,
911
+ "100.82.122.125:4500:tls" ,
912
+ "100.82.76.240:4500:tls" ,
913
+ }))
914
+ })
915
+ })
916
+
917
+ When ("the input is valid with DNS entries" , func () {
918
+ BeforeEach (func () {
919
+ input = "fdb_cluster_52v1bpr8:rhUbBjrtyweZBQO1U3Td81zyP9d46yEh@coordinator1.test.svc.cluster.local:4500:tls,coordinator2.test.svc.cluster.local:4500:tls,coordinator2.test.svc.cluster.local:4500:tls"
920
+ })
921
+
922
+ It ("should be parsed correctly" , func () {
923
+ Expect (err ).NotTo (HaveOccurred ())
924
+ Expect (str .DatabaseName ).To (Equal ("fdb_cluster_52v1bpr8" ))
925
+ Expect (str .GenerationID ).To (Equal ("rhUbBjrtyweZBQO1U3Td81zyP9d46yEh" ))
926
+ Expect (str .Coordinators ).To (ConsistOf ([]string {
927
+ "coordinator1.test.svc.cluster.local:4500:tls" ,
928
+ "coordinator2.test.svc.cluster.local:4500:tls" ,
929
+ "coordinator2.test.svc.cluster.local:4500:tls" ,
930
+ }))
931
+ })
932
+ })
933
+
934
+ When ("the input is valid with IPv6 entries" , func () {
935
+ BeforeEach (func () {
936
+ input = "fdb_cluster_52v1bpr8:rhUbBjrtyweZBQO1U3Td81zyP9d46yEh@[0100::2]:4500:tls,[0100::3]:4500:tls,[0100::4]:4500:tls"
937
+ })
938
+
939
+ It ("should be parsed correctly" , func () {
940
+ Expect (err ).NotTo (HaveOccurred ())
941
+ Expect (str .DatabaseName ).To (Equal ("fdb_cluster_52v1bpr8" ))
942
+ Expect (str .GenerationID ).To (Equal ("rhUbBjrtyweZBQO1U3Td81zyP9d46yEh" ))
943
+ Expect (str .Coordinators ).To (ConsistOf ([]string {
944
+ "[100::2]:4500:tls" ,
945
+ "[100::3]:4500:tls" ,
946
+ "[100::4]:4500:tls" ,
947
+ }))
948
+ })
949
+ })
950
+
951
+ When ("the input is valid with IPv6 and IPv4 entries" , func () {
952
+ BeforeEach (func () {
953
+ input = "fdb_cluster_52v1bpr8:[email protected] :4500:tls,100.82.71.5:4500:tls,100.82.119.151:4500:tls,[0100::3]:4500:tls,[0100::4]:4500:tls"
954
+ })
955
+
956
+ It ("should be parsed correctly" , func () {
957
+ Expect (err ).NotTo (HaveOccurred ())
958
+ Expect (str .DatabaseName ).To (Equal ("fdb_cluster_52v1bpr8" ))
959
+ Expect (str .GenerationID ).To (Equal ("rhUbBjrtyweZBQO1U3Td81zyP9d46yEh" ))
960
+ Expect (str .Coordinators ).To (ConsistOf ([]string {
961
+ "100.82.81.253:4500:tls" ,
962
+ "100.82.71.5:4500:tls" ,
963
+ "100.82.119.151:4500:tls" ,
964
+ "[100::3]:4500:tls" ,
965
+ "[100::4]:4500:tls" ,
966
+ }))
967
+ })
824
968
})
825
969
})
826
970
971
+ DescribeTable ("sanitize connection string description" , func (input string , expected string ) {
972
+ Expect (SanitizeConnectionStringDescription (input )).To (Equal (expected ))
973
+ },
974
+ Entry ("without hyphen" , "test" , "test" ),
975
+ Entry ("with hyphen" , "test-string" , "test_string" ),
976
+ )
977
+
827
978
When ("formatting the connection string" , func () {
828
979
It ("should be formatted correctly" , func () {
829
980
str := ConnectionString {
830
981
DatabaseName : "test" ,
831
982
GenerationID : "abcd" ,
832
- Coordinators : coordinatorsStr ,
983
+ Coordinators : coordinatorsList ,
833
984
}
834
985
Expect (
str .
String ()).
To (
Equal (
"test:[email protected] :4500,127.0.0.2:4500,127.0.0.3:4500" ))
835
986
})
@@ -840,7 +991,7 @@ var _ = Describe("[api] FoundationDBCluster", func() {
840
991
str := ConnectionString {
841
992
DatabaseName : "test" ,
842
993
GenerationID : "abcd" ,
843
- Coordinators : coordinatorsStr ,
994
+ Coordinators : coordinatorsList ,
844
995
}
845
996
err := str .GenerateNewGenerationID ()
846
997
Expect (err ).NotTo (HaveOccurred ())
@@ -853,7 +1004,7 @@ var _ = Describe("[api] FoundationDBCluster", func() {
853
1004
str := ConnectionString {
854
1005
DatabaseName : "test" ,
855
1006
GenerationID : "abcd" ,
856
- Coordinators : coordinatorsStr ,
1007
+ Coordinators : coordinatorsList ,
857
1008
}
858
1009
Expect (str .HasCoordinators (coordinators )).To (BeTrue ())
859
1010
// We have to copy the slice to prevent to modify the original slice
0 commit comments