xorm/dialects/table_name_test.go

38 lines
1.1 KiB
Go
Raw Normal View History

2018-04-11 05:53:09 +00:00
// Copyright 2018 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 dialects
2018-04-11 05:53:09 +00:00
import (
"context"
2018-04-11 05:53:09 +00:00
"testing"
"xorm.io/xorm/names"
2018-04-11 05:53:09 +00:00
"github.com/stretchr/testify/assert"
)
type MCC struct {
ID int64 `xorm:"pk 'id'"`
Code string `xorm:"'code'"`
Description string `xorm:"'description'"`
}
func (mcc *MCC) TableName() string {
return "mcc"
}
func TestFullTableName(t *testing.T) {
dialect, err := OpenDialect("mysql", "root:root@tcp(127.0.0.1:3306)/test?charset=utf8")
if err != nil {
panic("unknow dialect")
}
dialect.SetShadowable(NewTrueShadow())
assert.EqualValues(t, "shadow_test.mcc", FullTableName(context.Background(), dialect, names.SnakeMapper{}, &MCC{}))
assert.EqualValues(t, "shadow_test.mcc", FullTableName(context.Background(), dialect, names.SnakeMapper{}, "mcc"))
dialect.SetShadowable(NewFalseShadow())
assert.EqualValues(t, "mcc", FullTableName(context.Background(), dialect, names.SnakeMapper{}, &MCC{}))
assert.EqualValues(t, "mcc", FullTableName(context.Background(), dialect, names.SnakeMapper{}, "mcc"))
2018-04-11 05:53:09 +00:00
}