diff --git a/internal/display/members.go b/internal/display/members.go index b232ef401..dab543aa6 100644 --- a/internal/display/members.go +++ b/internal/display/members.go @@ -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(), diff --git a/internal/display/members_test.go b/internal/display/members_test.go new file mode 100644 index 000000000..dc2f63012 --- /dev/null +++ b/internal/display/members_test.go @@ -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) +}