@@ -25,7 +25,7 @@ import (
2525)
2626
2727func TestProductionAtlasDeployments_ListDeploymentConnections (t * testing.T ) {
28- t .Run ("Shouldn't call the serverless api if running in Gov" , func (t * testing.T ) {
28+ t .Run ("Shouldn't call the serverless or flex api if running in Gov" , func (t * testing.T ) {
2929 mockClustersAPI := mockadmin .NewClustersApi (t )
3030 mockClustersAPI .EXPECT ().ListClusters (context .Background (), mock .Anything ).Return (
3131 admin.ListClustersApiRequest {ApiService : mockClustersAPI })
@@ -34,17 +34,20 @@ func TestProductionAtlasDeployments_ListDeploymentConnections(t *testing.T) {
3434
3535 mockServerlessAPI := mockadmin .NewServerlessInstancesApi (t )
3636 mockServerlessAPI .EXPECT ().ListServerlessInstancesExecute (mock .Anything ).Unset ()
37+ mockFlexAPI := mockadminv20241113001 .NewFlexClustersApi (t )
38+ mockFlexAPI .EXPECT ().ListFlexClustersExecute (mock .Anything ).Unset ()
3739 ds := & ProductionAtlasDeployments {
3840 clustersAPI : mockClustersAPI ,
3941 serverlessAPI : mockServerlessAPI ,
42+ flexAPI : mockFlexAPI ,
4043 isGov : true ,
4144 }
4245 projectID := "testProjectID"
4346 _ , err := ds .ListDeploymentConnections (context .Background (), projectID )
4447 assert .Nil (t , err )
4548 })
4649
47- t .Run ("Should call the serverless api if not running in Gov" , func (t * testing.T ) {
50+ t .Run ("Should call the serverless and flex apis if not running in Gov" , func (t * testing.T ) {
4851 mockClustersAPI := mockadmin .NewClustersApi (t )
4952 mockClustersAPI .EXPECT ().ListClusters (context .Background (), mock .Anything ).Return (
5053 admin.ListClustersApiRequest {ApiService : mockClustersAPI })
@@ -57,15 +60,78 @@ func TestProductionAtlasDeployments_ListDeploymentConnections(t *testing.T) {
5760 mockServerlessAPI .EXPECT ().ListServerlessInstancesExecute (
5861 admin.ListServerlessInstancesApiRequest {ApiService : mockServerlessAPI }).Return (
5962 nil , & http.Response {StatusCode : http .StatusOK }, nil )
63+
64+ mockFlexAPI := mockadminv20241113001 .NewFlexClustersApi (t )
65+ mockFlexAPI .EXPECT ().ListFlexClusters (context .Background (), mock .Anything ).Return (
66+ adminv20241113001.ListFlexClustersApiRequest {ApiService : mockFlexAPI })
67+ mockFlexAPI .EXPECT ().ListFlexClustersExecute (
68+ adminv20241113001.ListFlexClustersApiRequest {ApiService : mockFlexAPI }).Return (
69+ nil , & http.Response {StatusCode : http .StatusOK }, nil )
70+
6071 ds := & ProductionAtlasDeployments {
6172 clustersAPI : mockClustersAPI ,
6273 serverlessAPI : mockServerlessAPI ,
74+ flexAPI : mockFlexAPI ,
6375 isGov : false ,
6476 }
6577 projectID := "testProjectID"
6678 _ , err := ds .ListDeploymentConnections (context .Background (), projectID )
6779 assert .Nil (t , err )
6880 })
81+
82+ t .Run ("Should create connection for each cluster type" , func (t * testing.T ) {
83+ mockClustersAPI := mockadmin .NewClustersApi (t )
84+ mockClustersAPI .EXPECT ().ListClusters (context .Background (), mock .Anything ).Return (
85+ admin.ListClustersApiRequest {ApiService : mockClustersAPI })
86+ mockClustersAPI .EXPECT ().ListClustersExecute (admin.ListClustersApiRequest {ApiService : mockClustersAPI }).Return (
87+ & admin.PaginatedAdvancedClusterDescription {
88+ Results : & []admin.AdvancedClusterDescription {
89+ {
90+ Name : pointer .MakePtr ("testCluster" ),
91+ ConnectionStrings : & admin.ClusterConnectionStrings {StandardSrv : pointer .MakePtr ("clusterSRV" )},
92+ },
93+ },
94+ }, & http.Response {StatusCode : http .StatusOK }, nil )
95+
96+ mockServerlessAPI := mockadmin .NewServerlessInstancesApi (t )
97+ mockServerlessAPI .EXPECT ().ListServerlessInstances (context .Background (), mock .Anything ).Return (
98+ admin.ListServerlessInstancesApiRequest {ApiService : mockServerlessAPI })
99+ mockServerlessAPI .EXPECT ().ListServerlessInstancesExecute (
100+ admin.ListServerlessInstancesApiRequest {ApiService : mockServerlessAPI }).Return (
101+ & admin.PaginatedServerlessInstanceDescription {
102+ Results : & []admin.ServerlessInstanceDescription {
103+ {
104+ Name : pointer .MakePtr ("testServerless" ),
105+ ConnectionStrings : & admin.ServerlessInstanceDescriptionConnectionStrings {StandardSrv : pointer .MakePtr ("serverlessSRV" )},
106+ },
107+ },
108+ }, & http.Response {StatusCode : http .StatusOK }, nil )
109+
110+ mockFlexAPI := mockadminv20241113001 .NewFlexClustersApi (t )
111+ mockFlexAPI .EXPECT ().ListFlexClusters (context .Background (), mock .Anything ).Return (
112+ adminv20241113001.ListFlexClustersApiRequest {ApiService : mockFlexAPI })
113+ mockFlexAPI .EXPECT ().ListFlexClustersExecute (
114+ adminv20241113001.ListFlexClustersApiRequest {ApiService : mockFlexAPI }).Return (
115+ & adminv20241113001.PaginatedFlexClusters20241113 {
116+ Results : & []adminv20241113001.FlexClusterDescription20241113 {
117+ {
118+ Name : pointer .MakePtr ("testFlex" ),
119+ ConnectionStrings : & adminv20241113001.FlexConnectionStrings20241113 {StandardSrv : pointer .MakePtr ("flexSRV" )},
120+ },
121+ },
122+ }, & http.Response {StatusCode : http .StatusOK }, nil )
123+
124+ ds := & ProductionAtlasDeployments {
125+ clustersAPI : mockClustersAPI ,
126+ serverlessAPI : mockServerlessAPI ,
127+ flexAPI : mockFlexAPI ,
128+ isGov : false ,
129+ }
130+ projectID := "testProjectID"
131+ conns , err := ds .ListDeploymentConnections (context .Background (), projectID )
132+ assert .Nil (t , err )
133+ assert .Equal (t , len (conns ), 3 )
134+ })
69135}
70136
71137func TestClusterExists (t * testing.T ) {
0 commit comments