From d91c80facb07985a387dc2d8165a82b5ceb6fd1d Mon Sep 17 00:00:00 2001 From: coderGo93 Date: Wed, 16 Jun 2021 19:24:34 -0600 Subject: [PATCH] added deleted function (#210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Edgar López --- ...cloud_provider_snapshot_backup_policies.go | 28 +++++++++ ..._provider_snapshot_backup_policies_test.go | 63 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/mongodbatlas/cloud_provider_snapshot_backup_policies.go b/mongodbatlas/cloud_provider_snapshot_backup_policies.go index 2dee9c563..f69f8e318 100644 --- a/mongodbatlas/cloud_provider_snapshot_backup_policies.go +++ b/mongodbatlas/cloud_provider_snapshot_backup_policies.go @@ -31,6 +31,7 @@ const ( type CloudProviderSnapshotBackupPoliciesService interface { Get(context.Context, string, string) (*CloudProviderSnapshotBackupPolicy, *Response, error) Update(context.Context, string, string, *CloudProviderSnapshotBackupPolicy) (*CloudProviderSnapshotBackupPolicy, *Response, error) + Delete(context.Context, string, string) (*CloudProviderSnapshotBackupPolicy, *Response, error) } // CloudProviderSnapshotBackupPoliciesServiceOp handles communication with the CloudProviderSnapshotBackupPoliciesService related methods of the @@ -120,3 +121,30 @@ func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Update(ctx context.Contex return root, resp, err } + +// Delete deletes all cloud backup schedules. +// +// See more: https://docs.atlas.mongodb.com/reference/api/cloud-backup/schedule/delete-all-schedules/ +func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Delete(ctx context.Context, groupID, clusterName string) (*CloudProviderSnapshotBackupPolicy, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupId", "must be set") + } + if clusterName == "" { + return nil, nil, NewArgError("clusterName", "must be set") + } + + path := fmt.Sprintf(cloudProviderSnapshotBackupPolicesBasePath, groupID, clusterName) + + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(CloudProviderSnapshotBackupPolicy) + resp, err := s.Client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} diff --git a/mongodbatlas/cloud_provider_snapshot_backup_policies_test.go b/mongodbatlas/cloud_provider_snapshot_backup_policies_test.go index 5e2a993f1..e086be1f6 100644 --- a/mongodbatlas/cloud_provider_snapshot_backup_policies_test.go +++ b/mongodbatlas/cloud_provider_snapshot_backup_policies_test.go @@ -296,3 +296,66 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) { t.Error(diff) } } + +func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + groupID := "5b6212af90dc76637950a2c6" + clusterName := "myCluster" + + path := fmt.Sprintf("/groups/%s/clusters/%s/backup/schedule", groupID, clusterName) + + mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodDelete) + + fmt.Fprint(w, `{ + "clusterId": "5e2f1bcaf38990fab9227b8", + "clusterName": "myCluster", + "links": [ + { + "href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/5dd5a6a472efab1d71a58495/clusters/myCluster/backup/schedule", + "rel": "self" + }, + { + "href": "https://cloud.mongodb.com/api/public/v1.0/groups/5dd5a6a472efab1d71a58495", + "rel": "http://mms.mongodb.com/group" + } + ], + "nextSnapshot": "2020-01-28T05:24:25Z", + "policies": [ + { + "id": "5e2f1bcaf38990fab9227b8", + "policyItems": [] + } + ], + "referenceHourOfDay": 17, + "referenceMinuteOfHour": 24, + "restoreWindowDays": 7 + }`) + }) + + cloudProviderSnapshot, _, err := client.CloudProviderSnapshotBackupPolicies.Delete(ctx, groupID, clusterName) + if err != nil { + t.Fatalf("CloudProviderSnapshotBackupPolicies.Update returned error: %v", err) + } + + expected := &CloudProviderSnapshotBackupPolicy{ + ClusterID: "5e2f1bcaf38990fab9227b8", + ClusterName: "myCluster", + NextSnapshot: "2020-01-28T05:24:25Z", + Policies: []Policy{ + { + ID: "5e2f1bcaf38990fab9227b8", + PolicyItems: []PolicyItem{}, + }, + }, + ReferenceHourOfDay: pointy.Int64(17), + ReferenceMinuteOfHour: pointy.Int64(24), + RestoreWindowDays: pointy.Int64(7), + } + + if diff := deep.Equal(cloudProviderSnapshot, expected); diff != nil { + t.Error(diff) + } +}