Skip to content

Commit

Permalink
added deleted function (#210)
Browse files Browse the repository at this point in the history
Co-authored-by: Edgar López <edgarlopez@pop-os.localdomain>
  • Loading branch information
coderGo93 and Edgar López committed Jun 17, 2021
1 parent ed77f8f commit d91c80f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mongodbatlas/cloud_provider_snapshot_backup_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
63 changes: 63 additions & 0 deletions mongodbatlas/cloud_provider_snapshot_backup_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit d91c80f

Please sign in to comment.