32 lines
461 B
Go
32 lines
461 B
Go
package goref_test
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"gitter.top/common/goref"
|
|
"testing"
|
|
)
|
|
|
|
func TestSliceStructToMap(t *testing.T) {
|
|
type T struct {
|
|
Id string
|
|
}
|
|
var a []T
|
|
a = append(a, T{
|
|
Id: "1",
|
|
})
|
|
a = append(a, T{
|
|
Id: "2",
|
|
})
|
|
a = append(a, T{
|
|
Id: "3",
|
|
})
|
|
a = append(a, T{
|
|
Id: "4",
|
|
})
|
|
|
|
var bind = make(map[string]T)
|
|
err := goref.SliceStructToMap(a, &bind, "Id")
|
|
assert.NoError(t, err)
|
|
t.Logf("map: %#v", bind["1"])
|
|
}
|