Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Add permanently delete opt
Browse files Browse the repository at this point in the history
  • Loading branch information
RicePatrick committed Mar 4, 2024
1 parent dc6dc0e commit ef1ada1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
12 changes: 10 additions & 2 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,17 +560,25 @@ func (s *GroupsService) UploadAvatar(gid interface{}, avatar io.Reader, filename
return g, resp, nil
}

// DeleteGroupOptions represents the available DeleteGroup() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#update-group
type DeleteGroupOptions struct {
PermanentlyRemove *bool `url:"permanently_remove,omitempty" json:"permanently_remove,omitempty"`
FullPath *string `url:"full_path,omitempty" json:"full_path,omitempty"`
}

// DeleteGroup removes group with all projects inside.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#remove-group
func (s *GroupsService) DeleteGroup(gid interface{}, options ...RequestOptionFunc) (*Response, error) {
func (s *GroupsService) DeleteGroup(gid interface{}, opt *DeleteGroupOptions, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s", PathEscape(group))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
if err != nil {
return nil, err
}
Expand Down
45 changes: 44 additions & 1 deletion groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitlab
import (
"fmt"
"net/http"
"net/url"
"reflect"
"testing"
)
Expand Down Expand Up @@ -145,7 +146,7 @@ func TestDeleteGroup(t *testing.T) {
w.WriteHeader(http.StatusAccepted)
})

resp, err := client.Groups.DeleteGroup(1)
resp, err := client.Groups.DeleteGroup(1, nil)
if err != nil {
t.Errorf("Groups.DeleteGroup returned error: %v", err)
}
Expand All @@ -157,6 +158,48 @@ func TestDeleteGroup(t *testing.T) {
}
}

func TestDeleteGroup_WithPermanentDelete(t *testing.T) {
mux, client := setup(t)
var params url.Values

mux.HandleFunc("/api/v4/groups/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
w.WriteHeader(http.StatusAccepted)

// Get the request parameters
parsedParams, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
t.Errorf("Groups.DeleteGroup returned error when parsing test parameters: %v", err)
}
params = parsedParams
})

resp, err := client.Groups.DeleteGroup(1, &DeleteGroupOptions{
PermanentlyRemove: Ptr(true),
FullPath: Ptr("testPath"),
})

if err != nil {
t.Errorf("Groups.DeleteGroup returned error: %v", err)
}

// Test that our status code matches
if resp.StatusCode != http.StatusAccepted {
t.Errorf("Groups.DeleteGroup returned %d, want %d", resp.StatusCode, http.StatusAccepted)
}

// Test that "permanently_remove" is set to true
if params.Get("permanently_remove") != "true" {
t.Errorf("Groups.DeleteGroup returned %v, want %v", params.Get("permanently_remove"), true)
}

// Test that "full_path" is set to "testPath"
if params.Get("full_path") != "testPath" {
t.Errorf("Groups.DeleteGroup returned %v, want %v", params.Get("full_path"), "testPath")
}
}

func TestSearchGroup(t *testing.T) {
mux, client := setup(t)

Expand Down

0 comments on commit ef1ada1

Please sign in to comment.