From c3c208411babf75cc5daad33c0168ee7c6c2bfda Mon Sep 17 00:00:00 2001 From: Jumpei Matsuda Date: Mon, 25 Jul 2022 13:37:54 +0900 Subject: [PATCH] fix: Don't use meaningless slice pointers and reflect package --- usergroups.go | 11 +++++------ usergroups_test.go | 7 ++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/usergroups.go b/usergroups.go index 2990421e2..c5d7a176b 100644 --- a/usergroups.go +++ b/usergroups.go @@ -3,7 +3,6 @@ package slack import ( "context" "net/url" - "reflect" "strings" ) @@ -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 } } @@ -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, ",")} } diff --git a/usergroups_test.go b/usergroups_test.go index d98ca257e..9586cf167 100644 --- a/usergroups_test.go +++ b/usergroups_test.go @@ -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 @@ -244,7 +241,7 @@ func TestUpdateUserGroup(t *testing.T) { { []UpdateUserGroupsOption{ UpdateUserGroupsOptionDescription(&presenceDescription), - UpdateUserGroupsOptionChannels(&presenceChannels), + UpdateUserGroupsOptionChannels([]string{"channel1", "channel2"}), }, map[string]string{ "token": "testing-token", @@ -256,7 +253,7 @@ func TestUpdateUserGroup(t *testing.T) { { []UpdateUserGroupsOption{ UpdateUserGroupsOptionDescription(&emptyDescription), - UpdateUserGroupsOptionChannels(&emptyChannels), + UpdateUserGroupsOptionChannels([]string{}), }, map[string]string{ "token": "testing-token",