Skip to content

Commit d8b9275

Browse files
authored
feat: add test failover method (#343)
1 parent 65479ce commit d8b9275

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

mongodbatlas/advanced_clusters.go

+26
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type AdvancedClustersService interface {
3333
Create(ctx context.Context, groupID string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
3434
Update(ctx context.Context, groupID, clusterName string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
3535
Delete(ctx context.Context, groupID, clusterName string) (*Response, error)
36+
TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error)
3637
}
3738

3839
// AdvancedClustersServiceOp handles communication with the Cluster (Advanced) related methods
@@ -246,3 +247,28 @@ func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, cluster
246247

247248
return resp, err
248249
}
250+
251+
// TestFailover starts a failover test for the specified cluster in the specified project
252+
//
253+
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Multi-Cloud-Clusters/operation/testFailover
254+
func (s *AdvancedClustersServiceOp) TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error) {
255+
if groupID == "" {
256+
return nil, NewArgError("groupId", "must be set")
257+
}
258+
if clusterName == "" {
259+
return nil, NewArgError("clusterName", "must be set")
260+
}
261+
262+
basePath := fmt.Sprintf(advancedClustersPath, groupID)
263+
escapedEntry := url.PathEscape(clusterName)
264+
path := fmt.Sprintf("%s/%s/restartPrimaries", basePath, escapedEntry)
265+
266+
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, nil)
267+
if err != nil {
268+
return nil, err
269+
}
270+
271+
resp, err := s.Client.Do(ctx, req, nil)
272+
273+
return resp, err
274+
}

mongodbatlas/advanced_clusters_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -1246,3 +1246,17 @@ func TestAdvancedClusters_Delete(t *testing.T) {
12461246
t.Fatalf("Cluster.Delete returned error: %v", err)
12471247
}
12481248
}
1249+
1250+
func TestFailover(t *testing.T) {
1251+
client, mux, teardown := setup()
1252+
defer teardown()
1253+
1254+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/restartPrimaries", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
1255+
testMethod(t, r, http.MethodPost)
1256+
})
1257+
1258+
_, err := client.AdvancedClusters.TestFailover(ctx, groupID, clusterName)
1259+
if err != nil {
1260+
t.Fatalf("Cluster.TestFailover returned error: %v", err)
1261+
}
1262+
}

0 commit comments

Comments
 (0)