Add test to reproduce missing TableName function
This commit is contained in:
parent
a29ac54e48
commit
d14e48cdd9
50
table_test.go
Normal file
50
table_test.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package gorm_test
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
type Example struct {
|
||||||
|
Id uint64 `gorm:"column:id; primary_key:yes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Example) TableName() string {
|
||||||
|
return "exampling"
|
||||||
|
}
|
||||||
|
|
||||||
|
//Test to reproduce invalid/non-existant TableName behaviour
|
||||||
|
func TestInsertWithTableName(t *testing.T) {
|
||||||
|
DB.Exec("drop table examples;")
|
||||||
|
DB.Exec("drop table exampling;")
|
||||||
|
|
||||||
|
exampling := Example{}
|
||||||
|
|
||||||
|
if err := DB.CreateTable(exampling).Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Save(exampling).Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Exec("SELECT count(*) from exampling;").Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInsertWithTableNameExplicit(t *testing.T) {
|
||||||
|
DB.Exec("drop table examples;")
|
||||||
|
DB.Exec("drop table exampling;")
|
||||||
|
|
||||||
|
exampling := Example{}
|
||||||
|
|
||||||
|
if err := DB.Table("exampling").CreateTable(exampling).Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Table("exampling").Save(exampling).Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := DB.Exec("SELECT count(*) from exampling;").Error; err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user