github.com/blend/go-sdk@v1.20220411.3/db/reflection_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package db 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func TestReflectSliceType(t *testing.T) { 17 its := assert.New(t) 18 19 objects := []benchObj{ 20 {}, {}, {}, 21 } 22 23 ot := ReflectSliceType(objects) 24 its.Equal("benchObj", ot.Name()) 25 } 26 27 func TestMakeSliceOfType(t *testing.T) { 28 its := assert.New(t) 29 tx, txErr := defaultDB().Begin() 30 its.Nil(txErr) 31 defer func() { 32 its.Nil(tx.Rollback()) 33 }() 34 35 seedErr := seedObjects(10, tx) 36 its.Nil(seedErr) 37 38 myType := ReflectType(benchObj{}) 39 sliceOfT, castOk := makeSliceOfType(myType).(*[]benchObj) 40 its.True(castOk) 41 42 allErr := defaultDB().Invoke(OptTx(tx)).All(sliceOfT) 43 its.Nil(allErr) 44 its.NotEmpty(*sliceOfT) 45 }