Skip to content

Commit

Permalink
Format filter param slice as comma separated string
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasslash committed May 5, 2022
1 parent bb26a1e commit 1f33aab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
13 changes: 10 additions & 3 deletions organization_membership_integration_test.go
Expand Up @@ -78,13 +78,20 @@ func TestOrganizationMembershipsList(t *testing.T) {
memTest2, memTest2Cleanup := createOrganizationMembership(t, client, orgTest)
defer memTest2Cleanup()

memTest3, memTest3Cleanup := createOrganizationMembership(t, client, orgTest)
defer memTest3Cleanup()

memTest2.User = &User{ID: memTest2.User.ID}
memTest3.User = &User{ID: memTest3.User.ID}

ml, err := client.OrganizationMemberships.List(ctx, orgTest.Name, &OrganizationMembershipListOptions{
Emails: []string{memTest2.Email},
Emails: []string{memTest2.Email, memTest3.Email},
})
require.NoError(t, err)

assert.Len(t, ml.Items, 1)
assert.Equal(t, ml.Items[0].ID, memTest2.ID)
assert.Len(t, ml.Items, 2)
assert.Contains(t, ml.Items, memTest2)
assert.Contains(t, ml.Items, memTest3)

t.Run("with invalid email", func(t *testing.T) {
ml, err = client.OrganizationMemberships.List(ctx, orgTest.Name, &OrganizationMembershipListOptions{
Expand Down
7 changes: 5 additions & 2 deletions team_integration_test.go
Expand Up @@ -27,6 +27,8 @@ func TestTeamsList(t *testing.T) {
defer tmTest1Cleanup()
tmTest2, tmTest2Cleanup := createTeam(t, client, orgTest)
defer tmTest2Cleanup()
tmTest3, tmTest3Cleanup := createTeam(t, client, orgTest)
defer tmTest3Cleanup()

t.Run("without list options", func(t *testing.T) {
tl, err := client.Teams.List(ctx, orgTest.Name, nil)
Expand Down Expand Up @@ -56,11 +58,12 @@ func TestTeamsList(t *testing.T) {
assert.Equal(t, 2, tl.TotalCount)

tl, err = client.Teams.List(ctx, orgTest.Name, &TeamListOptions{
Names: []string{tmTest2.Name},
Names: []string{tmTest2.Name, tmTest3.Name},
})

assert.Equal(t, tl.Items, 1)
assert.Equal(t, tl.Items, 2)
assert.Contains(t, tl.Items, tmTest2)
assert.Contains(t, tl.Items, tmTest3)

t.Run("with invalid names query param", func(t *testing.T) {
// should return an error because we've included an empty string
Expand Down
6 changes: 5 additions & 1 deletion tfe.go
Expand Up @@ -551,7 +551,7 @@ func encodeQueryParams(v url.Values) string {
sort.Strings(keys)
for _, k := range keys {
vs := v[k]
if len(vs) > 1 && k == _includeQueryParam {
if len(vs) > 1 && validSliceKey(k) {
val := strings.Join(vs, ",")
vs = vs[:0]
vs = append(vs, val)
Expand Down Expand Up @@ -909,3 +909,7 @@ func packContents(path string) (*bytes.Buffer, error) {

return body, nil
}

func validSliceKey(key string) bool {
return key == _includeQueryParam || strings.Contains(key, "filter[")
}

0 comments on commit 1f33aab

Please sign in to comment.