1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-27 10:41:32 +00:00
Beego/client/orm/model_utils_test.go

63 lines
1.5 KiB
Go
Raw Normal View History

2020-08-10 15:04:57 +00:00
// Copyright 2020
2020-07-28 06:28:51 +00:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package orm
import (
"testing"
"github.com/stretchr/testify/assert"
)
type Interface struct {
Id int
Name string
Index1 string
Index2 string
Unique1 string
Unique2 string
}
func (i *Interface) TableIndex() [][]string {
return [][]string{{"index1"}, {"index2"}}
}
func (i *Interface) TableUnique() [][]string {
return [][]string{{"unique1"}, {"unique2"}}
}
func (i *Interface) TableName() string {
return "INTERFACE_"
}
func (i *Interface) TableEngine() string {
return "innodb"
}
func TestDbBase_GetTables(t *testing.T) {
RegisterModel(&Interface{})
mi, ok := modelCache.get("INTERFACE_")
assert.True(t, ok)
assert.NotNil(t, mi)
engine := getTableEngine(mi.addrField)
assert.Equal(t, "innodb", engine)
uniques := getTableUnique(mi.addrField)
assert.Equal(t, [][]string{{"unique1"}, {"unique2"}}, uniques)
indexes := getTableIndex(mi.addrField)
assert.Equal(t, [][]string{{"index1"}, {"index2"}}, indexes)
}