Skip to content

Commit

Permalink
feat: Adding AutoDefer method to automatically defer any maintenance (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vicgp-te authored Jul 27, 2021
1 parent 34d12ee commit 4db32e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mongodbatlas/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type MaintenanceWindowsService interface {
Get(context.Context, string) (*MaintenanceWindow, *Response, error)
Update(context.Context, string, *MaintenanceWindow) (*Response, error)
Defer(context.Context, string) (*Response, error)
AutoDefer(context.Context, string) (*Response, error)
Reset(context.Context, string) (*Response, error)
}

Expand Down Expand Up @@ -132,6 +133,26 @@ func (s *MaintenanceWindowsServiceOp) Defer(ctx context.Context, groupID string)
return resp, err
}

// AutoDefer any scheduled maintenance for the given project for one week.
//
// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-window-auto-defer/
func (s *MaintenanceWindowsServiceOp) AutoDefer(ctx context.Context, groupID string) (*Response, error) {
if groupID == "" {
return nil, NewArgError("groupID", "cannot be nil")
}

path := fmt.Sprintf(maintenanceWindowsPath+"/autoDefer", groupID)

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
}

// Reset clears the current maintenance window for the given project.
//
// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-window-clear/
Expand Down
17 changes: 17 additions & 0 deletions mongodbatlas/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ func TestMaintenanceWindows_Defer(t *testing.T) {
}
}

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

groupID := "6d2065c687d9d64ae7acdg41"

mux.HandleFunc(fmt.Sprintf("/"+maintenanceWindowsPath+"/autoDefer", groupID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{}`)
})

_, err := client.MaintenanceWindows.AutoDefer(ctx, groupID)
if err != nil {
t.Errorf("MaintenanceWindows.AutoDefer returned error: %v", err)
}
}

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

0 comments on commit 4db32e8

Please sign in to comment.