Skip to content

Commit

Permalink
IAM Group: Fix retry call
Browse files Browse the repository at this point in the history
  • Loading branch information
loafoe committed Feb 4, 2023
1 parent e6c8256 commit 8c568cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 5 additions & 3 deletions iam/groups_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,17 @@ func (g *GroupsService) memberAction(ctx context.Context, group Group, action st
var memberResponse map[string]interface{}
var resp *Response

internal.TryHTTPCall(ctx, 6, func() (*http.Response, error) {
err = internal.TryHTTPCall(ctx, 6, func() (*http.Response, error) {
resp, err = g.client.do(req, &memberResponse)
if resp == nil {
return nil, err
}
if err != nil && err == io.EOF { // EOF is valid
err = nil
}
return resp.Response, err
})

if err != nil && err != io.EOF { // EOF is valid
if err != nil {
return memberResponse, resp, err
}
return memberResponse, resp, nil
Expand Down
11 changes: 8 additions & 3 deletions iam/groups_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ func TestAddMembers(t *testing.T) {
if resp != nil {
assert.Equal(t, http.StatusOK, resp.StatusCode())
}
if !assert.Nil(t, err) {
return
}
assert.Len(t, assignedTotal, 28)
assert.Nil(t, ok)
assert.Nil(t, err)
}

func TestRemoveMembers(t *testing.T) {
Expand Down Expand Up @@ -333,9 +335,11 @@ func TestRemoveMembers(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode())

ok, resp, err = client.Groups.RemoveMembers(context.Background(), group, "foo")
if !assert.NotNil(t, err) {
return
}
assert.NotNil(t, resp)
assert.Nil(t, ok)
assert.NotNil(t, err)
}

func TestRemoveRole(t *testing.T) {
Expand Down Expand Up @@ -393,9 +397,10 @@ func TestRemoveRole(t *testing.T) {
group.ID = groupID
role.ID = roleID
ok, resp, err := client.Groups.RemoveRole(group, role)
if !assert.Nil(t, err) {
}
assert.NotNil(t, resp)
assert.True(t, ok)
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode())
}

Expand Down

0 comments on commit 8c568cf

Please sign in to comment.