Skip to content

Commit

Permalink
fix: Handle Go SDK 204 no responses correctly (#1193)
Browse files Browse the repository at this point in the history
Changes copied from approved PR from forked repo #1074

Original commit message:
I added status code handling in the Go SDK to deal with delete endpoints' response body.
In Looker API, delete endpoints call returns empty response body with status code 204 when the API call is succeeded.
Such API call will be failed with EOF error in the current implementation because of reading empty response body.

Co-authored-by: hirohito-sasakawa <hirohito-sasakawa@m3.com>
Co-authored-by: hirosassa <hiro.sassa@gmail.com>
  • Loading branch information
3 people authored Oct 18, 2022
1 parent 051cf86 commit ba7ded8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
60 changes: 60 additions & 0 deletions go/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,66 @@ func TestIntegrationGoSDK(t *testing.T) {
}
})

t.Run("CRUD User Attribute Group Value", func(t *testing.T) {
name := "foo"
group, err := sdk.CreateGroup(v4.WriteGroup{
Name: &name,
}, "", nil)
if err != nil {
t.Errorf("CreateGroup() failed. error=%v", err)
}

groupId := group.Id
group, err = sdk.Group(*groupId, "", nil)
if err != nil {
t.Errorf("Group() failed. error=%v", err)
}

attributeName := "bar"
attributeLabel := "bar"
attributeType := "string"
ua, err := sdk.CreateUserAttribute(v4.WriteUserAttribute{
Name: attributeName,
Label: attributeLabel,
Type: attributeType,
}, "", nil)
if err != nil {
t.Errorf("CreateUserAttribute failed. error=%v", err)
}

uaId := ua.Id
ua, err = sdk.UserAttribute(*uaId, "", nil)
if err != nil {
t.Errorf("UserAttribute() failed. error=%v", err)
}

value := "baz"
_, err = sdk.UpdateUserAttributeGroupValue(*groupId, *uaId, v4.UserAttributeGroupValue{
GroupId: groupId,
UserAttributeId: uaId,
Value: &value,
}, nil)
if err != nil {
t.Errorf("UpdateUserAttributeGroupValue() failed. error=%v", err)
}

err = sdk.DeleteUserAttributeGroupValue(*groupId, *uaId, nil)
if err != nil {
t.Errorf("DeleteUserAttributeGroupValue() failed. error=%v", err)
}

_, err = sdk.DeleteUserAttribute(*uaId, nil)
if err != nil {
t.Errorf("DeleteUserAttribute() failed. error=%v", err)
}

_, err = sdk.DeleteGroup(*groupId, nil)
if err != nil {
t.Errorf("DeleteGroup() failed. error=%v", err)
}

})

t.Run("Me()", func(t *testing.T) {
user, err := sdk.Me("", nil)

Expand Down
4 changes: 4 additions & 0 deletions go/rtl/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (s *AuthSession) Do(result interface{}, method, ver, path string, reqPars m
return fmt.Errorf("response error. status=%s. error=%s", res.Status, string(b))
}

if res.StatusCode == 204 { // 204 No Content. DELETE endpoints returns response with no body
return nil
}

// TODO: Make parsing content-type aware. Requires change to go model generation to use interface{} for all union types.
// Github Issue: https://github.com/looker-open-source/sdk-codegen/issues/1022
switch v := result.(type) {
Expand Down

0 comments on commit ba7ded8

Please sign in to comment.