Skip to content

Commit

Permalink
feat: add test failover method (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn authored and wtrocki committed Feb 7, 2023
1 parent d21a6e9 commit 6b80142
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mongodbatlas/advanced_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type AdvancedClustersService interface {
Create(ctx context.Context, groupID string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
Update(ctx context.Context, groupID, clusterName string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
Delete(ctx context.Context, groupID, clusterName string) (*Response, error)
TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error)
}

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

return resp, err
}

// TestFailover starts a failover test for the specified cluster in the specified project
//
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Multi-Cloud-Clusters/operation/testFailover
func (s *AdvancedClustersServiceOp) TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error) {
if groupID == "" {
return nil, NewArgError("groupId", "must be set")
}
if clusterName == "" {
return nil, NewArgError("clusterName", "must be set")
}

basePath := fmt.Sprintf(advancedClustersPath, groupID)
escapedEntry := url.PathEscape(clusterName)
path := fmt.Sprintf("%s/%s/restartPrimaries", basePath, escapedEntry)

req, err := s.Client.NewRequest(ctx, http.MethodPost, path, nil)
if err != nil {
return nil, err
}

resp, err := s.Client.Do(ctx, req, nil)

return resp, err
}
14 changes: 14 additions & 0 deletions mongodbatlas/advanced_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,17 @@ func TestAdvancedClusters_Delete(t *testing.T) {
t.Fatalf("Cluster.Delete returned error: %v", err)
}
}

func TestFailover(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.5/groups/%s/clusters/%s/restartPrimaries", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
})

_, err := client.AdvancedClusters.TestFailover(ctx, groupID, clusterName)
if err != nil {
t.Fatalf("Cluster.TestFailover returned error: %v", err)
}
}

0 comments on commit 6b80142

Please sign in to comment.