Improve code quality

This commit is contained in:
fwhez 2018-11-12 11:12:32 +08:00
parent 300b6d385c
commit 28b35dae2a
2 changed files with 7 additions and 7 deletions

View File

@ -114,7 +114,7 @@ func (s *DB) CopyDB() (*sql.DB, error) {
if s.copyDB != nil { if s.copyDB != nil {
return s.copyDB, nil return s.copyDB, nil
} }
return sql.Open(s.Dialect().GetName(), s.DataSource()) return sql.Open(s.Dialect().GetName(), s.DataSource())
} }
type closer interface { type closer interface {

View File

@ -1061,8 +1061,8 @@ func TestBlockGlobalUpdate(t *testing.T) {
func TestDB_DataSource(t *testing.T) { func TestDB_DataSource(t *testing.T) {
source := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable" source := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable"
db,er := gorm.Open("postgres", source) db, er := gorm.Open("postgres", source)
if er!=nil { if er != nil {
panic(fmt.Sprintf("No error should happen when connecting to test database, but got err=%+v", er)) panic(fmt.Sprintf("No error should happen when connecting to test database, but got err=%+v", er))
} }
if db.DataSource() != source { if db.DataSource() != source {
@ -1072,12 +1072,12 @@ func TestDB_DataSource(t *testing.T) {
} }
func TestDB_CopyIn(t *testing.T) { func TestDB_CopyIn(t *testing.T) {
source := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable" source := "user=gorm password=gorm DB.name=gorm port=9920 sslmode=disable"
db,er := gorm.Open("postgres", source) db, er := gorm.Open("postgres", source)
if er!=nil { if er != nil {
panic(fmt.Sprintf("No error should happen when connecting to test database, but got err=%+v", er)) panic(fmt.Sprintf("No error should happen when connecting to test database, but got err=%+v", er))
} }
e:=db.Exec("create table if not exists example(name varchar, age integer)").Error e := db.Exec("create table if not exists example(name varchar, age integer)").Error
defer func(){ defer func() {
er := db.Exec("drop table if exists example").Error er := db.Exec("drop table if exists example").Error
if er != nil { if er != nil {
t.Fatal(e.Error()) t.Fatal(e.Error())