|
|
|
@ -8,34 +8,32 @@ import (
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
User struct {
|
|
|
|
|
// 自增id
|
|
|
|
|
Id string `db:"id" json:"id,omitempty"`
|
|
|
|
|
// 姓名
|
|
|
|
|
UserName string `db:"user_name" json:"userName,omitempty"`
|
|
|
|
|
// 1男,2女
|
|
|
|
|
Sex int `db:"sex" json:"sex,omitempty"`
|
|
|
|
|
|
|
|
|
|
Uuid string `db:"uuid" uuid:"uuid,omitempty"`
|
|
|
|
|
|
|
|
|
|
Age int `db:"age" json:"age"`
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
type mockedUser struct {
|
|
|
|
|
// 自增id
|
|
|
|
|
Id string `db:"id" json:"id,omitempty"`
|
|
|
|
|
// 姓名
|
|
|
|
|
UserName string `db:"user_name" json:"userName,omitempty"`
|
|
|
|
|
// 1男,2女
|
|
|
|
|
Sex int `db:"sex" json:"sex,omitempty"`
|
|
|
|
|
Uuid string `db:"uuid" uuid:"uuid,omitempty"`
|
|
|
|
|
Age int `db:"age" json:"age"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userFieldsWithRawStringQuote = RawFieldNames(User{})
|
|
|
|
|
var userFieldsWithoutRawStringQuote = FieldNames(User{})
|
|
|
|
|
var (
|
|
|
|
|
userFieldsWithRawStringQuote = RawFieldNames(mockedUser{})
|
|
|
|
|
userFieldsWithoutRawStringQuote = FieldNames(mockedUser{})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestFieldNames(t *testing.T) {
|
|
|
|
|
t.Run("old", func(t *testing.T) {
|
|
|
|
|
var u User
|
|
|
|
|
var u mockedUser
|
|
|
|
|
out := FieldNames(&u)
|
|
|
|
|
expected := []string{"id", "user_name", "sex", "uuid", "age"}
|
|
|
|
|
assert.Equal(t, expected, out)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("new", func(t *testing.T) {
|
|
|
|
|
var u User
|
|
|
|
|
var u mockedUser
|
|
|
|
|
out := RawFieldNames(&u)
|
|
|
|
|
expected := []string{"`id`", "`user_name`", "`sex`", "`uuid`", "`age`"}
|
|
|
|
|
assert.Equal(t, expected, out)
|
|
|
|
@ -43,7 +41,7 @@ func TestFieldNames(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNewEq(t *testing.T) {
|
|
|
|
|
u := &User{
|
|
|
|
|
u := &mockedUser{
|
|
|
|
|
Id: "123456",
|
|
|
|
|
UserName: "wahaha",
|
|
|
|
|
}
|
|
|
|
@ -55,7 +53,7 @@ func TestNewEq(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// @see https://github.com/go-xorm/builder
|
|
|
|
|
func TestBuilderSql(t *testing.T) {
|
|
|
|
|
u := &User{
|
|
|
|
|
u := &mockedUser{
|
|
|
|
|
Id: "123123",
|
|
|
|
|
}
|
|
|
|
|
fields := RawFieldNames(u)
|
|
|
|
@ -96,7 +94,7 @@ func TestBuildSqlDefaultValue(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuilderSqlIn(t *testing.T) {
|
|
|
|
|
u := &User{
|
|
|
|
|
u := &mockedUser{
|
|
|
|
|
Age: 18,
|
|
|
|
|
}
|
|
|
|
|
gtU := NewGt(u)
|
|
|
|
|