github.com/lingyao2333/mo-zero@v1.4.1/core/stores/builder/builder_test.go (about) 1 package builder 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 type mockedUser struct { 10 ID string `db:"id" json:"id,omitempty"` 11 UserName string `db:"user_name" json:"userName,omitempty"` 12 Sex int `db:"sex" json:"sex,omitempty"` 13 UUID string `db:"uuid" uuid:"uuid,omitempty"` 14 Age int `db:"age" json:"age"` 15 } 16 17 func TestFieldNames(t *testing.T) { 18 t.Run("new", func(t *testing.T) { 19 var u mockedUser 20 out := RawFieldNames(&u) 21 expected := []string{"`id`", "`user_name`", "`sex`", "`uuid`", "`age`"} 22 assert.Equal(t, expected, out) 23 }) 24 } 25 26 type mockedUserWithOptions struct { 27 ID string `db:"id" json:"id,omitempty"` 28 UserName string `db:"user_name,type=varchar,length=255" json:"userName,omitempty"` 29 Sex int `db:"sex" json:"sex,omitempty"` 30 UUID string `db:",type=varchar,length=16" uuid:"uuid,omitempty"` 31 Age int `db:"age" json:"age"` 32 } 33 34 func TestFieldNamesWithTagOptions(t *testing.T) { 35 t.Run("new", func(t *testing.T) { 36 var u mockedUserWithOptions 37 out := RawFieldNames(&u) 38 expected := []string{"`id`", "`user_name`", "`sex`", "`UUID`", "`age`"} 39 assert.Equal(t, expected, out) 40 }) 41 }