Improve code quality
This commit is contained in:
parent
fb7768f316
commit
14df8e1022
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
documents
|
||||
_book
|
||||
.idea/workspace.xml
|
||||
.idea/
|
||||
|
19
main_test.go
19
main_test.go
@ -1060,29 +1060,26 @@ func TestBlockGlobalUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDB_DataSource(t *testing.T) {
|
||||
source := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable"
|
||||
if DB.DataSource() != source {
|
||||
t.Fatal(fmt.Sprintf("want '%s', but got '%s'", source, DB.DataSource()))
|
||||
}
|
||||
|
||||
fmt.Println(DB.DataSource())
|
||||
}
|
||||
|
||||
type Example struct{
|
||||
type Example struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
func (e Example) TableName()string{
|
||||
|
||||
func (e Example) TableName() string {
|
||||
return "example"
|
||||
}
|
||||
func TestDB_CopyIn(t *testing.T) {
|
||||
if !DB.HasTable(&Example{}) {
|
||||
if e:=DB.Create(&Example{}).Error;e!=nil {
|
||||
if e := DB.CreateTable(&Example{}).Error; e != nil {
|
||||
t.Fatal(e.Error())
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
if DB.HasTable(&Example{}) {
|
||||
if e:=DB.DropTable(&Example{}).Error;e!=nil{
|
||||
if e := DB.DropTable(&Example{}).Error; e != nil {
|
||||
t.Fatal(e.Error())
|
||||
}
|
||||
}
|
||||
@ -1099,10 +1096,6 @@ func TestDB_CopyIn(t *testing.T) {
|
||||
if e != nil {
|
||||
t.Fatal(e.Error())
|
||||
}
|
||||
type Example struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
var examples = make([]Example, 0)
|
||||
e = DB.Model(&Example{}).Find(&examples).Error
|
||||
if e != nil {
|
||||
|
@ -294,7 +294,7 @@ func runMigration() {
|
||||
|
||||
values := []interface{}{&Short{}, &ReallyLongThingThatReferencesShort{}, &ReallyLongTableNameToTestMySQLNameLengthLimit{}, &NotSoLongTableName{}, &Product{}, &Email{}, &Address{}, &CreditCard{}, &Company{}, &Role{}, &Language{}, &HNPost{}, &EngadgetPost{}, &Animal{}, &User{}, &JoinTable{}, &Post{}, &Category{}, &Comment{}, &Cat{}, &Dog{}, &Hamster{}, &Toy{}, &ElementWithIgnoredField{}, &Place{}}
|
||||
for _, value := range values {
|
||||
if DB.HasTable(value){
|
||||
if DB.HasTable(value) {
|
||||
DB.DropTable(value)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user