github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/internal/examples/boilerplate/slice_namesbyRole_new_test.go (about)

     1  package boilerplate
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/m4gshm/gollections/slice/convert"
    10  	"github.com/m4gshm/gollections/slice/group"
    11  )
    12  
    13  func Test_NamesByRole_New(t *testing.T) {
    14  
    15  	var namesByRole = group.ByMultipleKeys(users, func(u User) []string {
    16  		return convert.AndConvert(u.Roles(), Role.Name, strings.ToLower)
    17  	}, User.Name)
    18  	// map[:[Tom] admin:[Bob] manager:[Bob Alice]]
    19  
    20  	assert.Equal(t, namesByRole[""], []string{"Tom"})
    21  	assert.Equal(t, namesByRole["manager"], []string{"Bob", "Alice"})
    22  	assert.Equal(t, namesByRole["admin"], []string{"Bob"})
    23  
    24  }