closes 5254: %COL% should be a common placeholder

This commit is contained in:
Deng Ming
2023-06-20 17:18:21 +08:00
parent bc7f6ffa1a
commit 3673a322a6
4 changed files with 46 additions and 3 deletions

View File

@@ -33,6 +33,11 @@ func getColumnTyp(al *alias, fi *models.FieldInfo) (col string) {
fieldType := fi.FieldType
fieldSize := fi.Size
defer func() {
// handling the placeholder, including %COL%
col = strings.ReplaceAll(col, "%COL%", fi.Column)
}()
checkColumn:
switch fieldType {
case TypeBooleanField:

View File

@@ -0,0 +1,37 @@
package orm
import (
"github.com/beego/beego/v2/client/orm/internal/models"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_getColumnTyp(t *testing.T) {
testCases := []struct {
name string
fi *models.FieldInfo
al *alias
wantCol string
}{
{
// https://github.com/beego/beego/issues/5254
name: "issue 5254",
fi: &models.FieldInfo{
FieldType: TypePositiveIntegerField,
Column: "my_col",
},
al: &alias{
DbBaser: newdbBasePostgres(),
},
wantCol: `bigint CHECK("my_col" >= 0)`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
col := getColumnTyp(tc.al, tc.fi)
assert.Equal(t, tc.wantCol, col)
})
}
}