@@ -25,7 +25,7 @@ import (
25
25
)
26
26
27
27
func 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 ) {
29
29
mockClustersAPI := mockadmin .NewClustersApi (t )
30
30
mockClustersAPI .EXPECT ().ListClusters (context .Background (), mock .Anything ).Return (
31
31
admin.ListClustersApiRequest {ApiService : mockClustersAPI })
@@ -34,17 +34,20 @@ func TestProductionAtlasDeployments_ListDeploymentConnections(t *testing.T) {
34
34
35
35
mockServerlessAPI := mockadmin .NewServerlessInstancesApi (t )
36
36
mockServerlessAPI .EXPECT ().ListServerlessInstancesExecute (mock .Anything ).Unset ()
37
+ mockFlexAPI := mockadminv20241113001 .NewFlexClustersApi (t )
38
+ mockFlexAPI .EXPECT ().ListFlexClustersExecute (mock .Anything ).Unset ()
37
39
ds := & ProductionAtlasDeployments {
38
40
clustersAPI : mockClustersAPI ,
39
41
serverlessAPI : mockServerlessAPI ,
42
+ flexAPI : mockFlexAPI ,
40
43
isGov : true ,
41
44
}
42
45
projectID := "testProjectID"
43
46
_ , err := ds .ListDeploymentConnections (context .Background (), projectID )
44
47
assert .Nil (t , err )
45
48
})
46
49
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 ) {
48
51
mockClustersAPI := mockadmin .NewClustersApi (t )
49
52
mockClustersAPI .EXPECT ().ListClusters (context .Background (), mock .Anything ).Return (
50
53
admin.ListClustersApiRequest {ApiService : mockClustersAPI })
@@ -57,15 +60,78 @@ func TestProductionAtlasDeployments_ListDeploymentConnections(t *testing.T) {
57
60
mockServerlessAPI .EXPECT ().ListServerlessInstancesExecute (
58
61
admin.ListServerlessInstancesApiRequest {ApiService : mockServerlessAPI }).Return (
59
62
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
+
60
71
ds := & ProductionAtlasDeployments {
61
72
clustersAPI : mockClustersAPI ,
62
73
serverlessAPI : mockServerlessAPI ,
74
+ flexAPI : mockFlexAPI ,
63
75
isGov : false ,
64
76
}
65
77
projectID := "testProjectID"
66
78
_ , err := ds .ListDeploymentConnections (context .Background (), projectID )
67
79
assert .Nil (t , err )
68
80
})
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
+ })
69
135
}
70
136
71
137
func TestClusterExists (t * testing.T ) {
0 commit comments