Skip to content

Commit

Permalink
fix: Don't use meaningless slice pointers and reflect package
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsu committed Jul 25, 2022
1 parent 38367d1 commit c3c2084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 5 additions & 6 deletions usergroups.go
Expand Up @@ -3,7 +3,6 @@ package slack
import (
"context"
"net/url"
"reflect"
"strings"
)

Expand Down Expand Up @@ -208,10 +207,10 @@ func UpdateUserGroupsOptionDescription(description *string) UpdateUserGroupsOpti
}
}

// UpdateUserGroupsOptionChannels change the default channels of the User Group. (default: nil, so it's no-op)
func UpdateUserGroupsOptionChannels(channels *[]string) UpdateUserGroupsOption {
// UpdateUserGroupsOptionChannels change the default channels of the User Group. (default: unspecified, so it's no-op)
func UpdateUserGroupsOptionChannels(channels []string) UpdateUserGroupsOption {
return func(params *UpdateUserGroupsParams) {
params.Channels = channels
params.Channels = &channels
}
}

Expand Down Expand Up @@ -249,11 +248,11 @@ func (api *Client) UpdateUserGroupContext(ctx context.Context, userGroupID strin
values["handle"] = []string{params.Handle}
}

if !reflect.ValueOf(params.Description).IsNil() {
if params.Description != nil {
values["description"] = []string{*params.Description}
}

if !reflect.ValueOf(params.Channels).IsNil() {
if params.Channels != nil {
values["channels"] = []string{strings.Join(*params.Channels, ",")}
}

Expand Down
7 changes: 2 additions & 5 deletions usergroups_test.go
Expand Up @@ -222,9 +222,6 @@ func TestUpdateUserGroup(t *testing.T) {
emptyDescription := ""
presenceDescription := "Marketing gurus, PR experts and product advocates."

emptyChannels := []string{}
presenceChannels := []string{"channel1", "channel2"}

tests := []struct {
options []UpdateUserGroupsOption
wantParams map[string]string
Expand All @@ -244,7 +241,7 @@ func TestUpdateUserGroup(t *testing.T) {
{
[]UpdateUserGroupsOption{
UpdateUserGroupsOptionDescription(&presenceDescription),
UpdateUserGroupsOptionChannels(&presenceChannels),
UpdateUserGroupsOptionChannels([]string{"channel1", "channel2"}),
},
map[string]string{
"token": "testing-token",
Expand All @@ -256,7 +253,7 @@ func TestUpdateUserGroup(t *testing.T) {
{
[]UpdateUserGroupsOption{
UpdateUserGroupsOptionDescription(&emptyDescription),
UpdateUserGroupsOptionChannels(&emptyChannels),
UpdateUserGroupsOptionChannels([]string{}),
},
map[string]string{
"token": "testing-token",
Expand Down

0 comments on commit c3c2084

Please sign in to comment.