xorm/table_name_test.go
Lunny Xiao 189e272774 Add tests for table name (#1517)
add tests for table name

Fix test (#1526)

Fix test

Reviewed-on: xorm/xorm#1526
2020-02-20 07:18:44 +00:00

74 lines
1.4 KiB
Go

// Copyright 2020 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)
type TestTableNameStruct struct{}
func (t *TestTableNameStruct) TableName() string {
return "my_test_table_name_struct"
}
func TestGetTableName(t *testing.T) {
var kases = []struct {
mapper core.IMapper
v reflect.Value
expectedTableName string
}{
{
core.SnakeMapper{},
reflect.ValueOf(new(Userinfo)),
"userinfo",
},
{
core.SnakeMapper{},
reflect.ValueOf(Userinfo{}),
"userinfo",
},
{
core.SameMapper{},
reflect.ValueOf(new(Userinfo)),
"Userinfo",
},
{
core.SameMapper{},
reflect.ValueOf(Userinfo{}),
"Userinfo",
},
{
core.SnakeMapper{},
reflect.ValueOf(new(MyGetCustomTableImpletation)),
getCustomTableName,
},
{
core.SnakeMapper{},
reflect.ValueOf(MyGetCustomTableImpletation{}),
getCustomTableName,
},
{
core.SnakeMapper{},
reflect.ValueOf(MyGetCustomTableImpletation{}),
getCustomTableName,
},
{
core.SnakeMapper{},
reflect.ValueOf(new(TestTableNameStruct)),
new(TestTableNameStruct).TableName(),
},
}
for _, kase := range kases {
assert.EqualValues(t, kase.expectedTableName, getTableName(kase.mapper, kase.v))
}
}