Skip to content

Commit

Permalink
Update to match API in master (15.3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhodgson authored and gravis committed Sep 1, 2022
1 parent da4ab38 commit 2a06d7a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
37 changes: 29 additions & 8 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,32 @@ func (s *GroupsService) ListGroupSAMLLinks(gid interface{}, options ...RequestOp
return gls, resp, nil
}

// GetGroupSAMLLink get a specific group SAML link. Available only for users who
// can edit groups.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#get-saml-group-link
func (s *GroupsService) GetGroupSAMLLink(gid interface{}, saml_group_name string, options ...RequestOptionFunc) (*SAMLGroupLink, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/saml_group_links/%s", PathEscape(group), PathEscape(saml_group_name))

req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
if err != nil {
return nil, nil, err
}

gl := new(SAMLGroupLink)
resp, err := s.client.Do(req, &gl)
if err != nil {
return nil, resp, err
}

return gl, resp, nil
}

// AddGroupSAMLLinkOptions represents the available AddGroupSAMLLink() options.
//
// GitLab API docs:
Expand All @@ -805,18 +831,13 @@ func (s *GroupsService) AddGroupSAMLLink(gid interface{}, opt *AddGroupSAMLLinkO
return nil, nil, err
}

resp, err := s.client.Do(req, nil)
gl := new(SAMLGroupLink)
resp, err := s.client.Do(req, &gl)
if err != nil {
return nil, resp, err
}

// The API returns a null response for new created objects, so we construct the result for a successfull post from the inputs.
gl := SAMLGroupLink{
AccessLevel: *opt.AccessLevel,
Name: *opt.SamlGroupName,
}

return &gl, resp, err
return gl, resp, err
}

// DeleteGroupSAMLLink deletes a group SAML link. Available only for users who
Expand Down
30 changes: 29 additions & 1 deletion groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,34 @@ func TestListGroupSAMLLinks(t *testing.T) {
}
}

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

mux.HandleFunc("/api/v4/groups/1/saml_group_links/gitlab_group_example_developer",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `
{
"access_level":"Developer",
"name":"gitlab_group_example_developer"
}`)
})

links, _, err := client.Groups.GetGroupSAMLLink(1, "gitlab_group_example_developer")
if err != nil {
t.Errorf("Groups.GetGroupSAMLLinks returned error: %v", err)
}

want := &SAMLGroupLink{
AccessLevel: "Developer",
Name: "gitlab_group_example_developer",
}
if !reflect.DeepEqual(want, links) {
t.Errorf("Groups.GetGroupSAMLLink returned %+v, want %+v", links, want)
}
}

func TestAddGroupSAMLLink(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
Expand All @@ -413,7 +441,7 @@ func TestAddGroupSAMLLink(t *testing.T) {
fmt.Fprint(w, `
{
"access_level":"Developer",
"saml_group_name":"gitlab_group_example_developer"
"name":"gitlab_group_example_developer"
}`)
})

Expand Down

0 comments on commit 2a06d7a

Please sign in to comment.