Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass by value in for loop, not by reference. #953

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 36 additions & 0 deletions internal/display/members_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package display

import (
"bytes"
"encoding/json"
"io"
"testing"

"github.com/auth0/go-auth0/management"
"github.com/stretchr/testify/assert"
)

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)
}
Loading