1 Star 0 Fork 1

flanche/gorm

forked from 听我一言/gorm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
naming_test.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
package gorm_test
import (
"testing"
"github.com/jinzhu/gorm"
)
func TestTheNamingStrategy(t *testing.T) {
cases := []struct {
name string
namer gorm.Namer
expected string
}{
{name: "auth", expected: "auth", namer: gorm.TheNamingStrategy.DB},
{name: "userRestrictions", expected: "user_restrictions", namer: gorm.TheNamingStrategy.Table},
{name: "clientID", expected: "client_id", namer: gorm.TheNamingStrategy.Column},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
result := c.namer(c.name)
if result != c.expected {
t.Errorf("error in naming strategy. expected: %v got :%v\n", c.expected, result)
}
})
}
}
func TestNamingStrategy(t *testing.T) {
dbNameNS := func(name string) string {
return "db_" + name
}
tableNameNS := func(name string) string {
return "tbl_" + name
}
columnNameNS := func(name string) string {
return "col_" + name
}
ns := &gorm.NamingStrategy{
DB: dbNameNS,
Table: tableNameNS,
Column: columnNameNS,
}
cases := []struct {
name string
namer gorm.Namer
expected string
}{
{name: "auth", expected: "db_auth", namer: ns.DB},
{name: "user", expected: "tbl_user", namer: ns.Table},
{name: "password", expected: "col_password", namer: ns.Column},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
result := c.namer(c.name)
if result != c.expected {
t.Errorf("error in naming strategy. expected: %v got :%v\n", c.expected, result)
}
})
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flanche/gorm.git
git@gitee.com:flanche/gorm.git
flanche
gorm
gorm
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385