Skip to content

Commit

Permalink
Pass by value in for loop, not by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Christenson II committed Dec 21, 2023
1 parent dfc8f5e commit 1526d5a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/display/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func (r *Renderer) MembersList(members []management.OrganizationMember) {

var res []View
for _, m := range members {
res = append(res, makeMembersView(&m))
res = append(res, makeMembersView(m))
}

r.Results(res)
}

func makeMembersView(member *management.OrganizationMember) *membersView {
func makeMembersView(member management.OrganizationMember) *membersView {
return &membersView{
ID: member.GetUserID(),
Name: member.GetName(),
Expand Down
35 changes: 35 additions & 0 deletions internal/display/members_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package display

import (
"bytes"
"encoding/json"
"github.com/auth0/go-auth0/management"
"github.com/stretchr/testify/assert"
"io"
"testing"
)

func TestRenderer_MembersList_json(t *testing.T) {
var input []management.OrganizationMember
for _, id := range []string{"1234", "5678"} {
nid := id
input = append(input, management.OrganizationMember{UserID: &nid})
}

var exp []interface{}
raw, _ := json.Marshal(input)
_ = json.Unmarshal(raw, &exp)

r := NewRenderer()
r.Format = OutputFormatJSON

out := bytes.NewBuffer([]byte{})
r.ResultWriter = out
r.MembersList(input)
buf, _ := io.ReadAll(out)

var got []interface{}
_ = json.Unmarshal(buf, &got)

assert.Equal(t, exp, got)
}

0 comments on commit 1526d5a

Please sign in to comment.