From d9161ec9487a22ace84f541bf7f980fc214a18b8 Mon Sep 17 00:00:00 2001 From: fwhez <1728565484@qq.com> Date: Mon, 12 Nov 2018 10:34:20 +0800 Subject: [PATCH] Use offical test DB instance --- main_test.go | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/main_test.go b/main_test.go index ab614254..6fe4a8dd 100644 --- a/main_test.go +++ b/main_test.go @@ -1060,26 +1060,14 @@ func TestBlockGlobalUpdate(t *testing.T) { } func TestDB_DataSource(t *testing.T) { - source := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=%s password=%s", - "localhost", "postgres", "test", "disable", "123") - db, er := gorm.Open("postgres", source) - if er != nil { - t.Fatal(er.Error()) - } - - if db.DataSource() != source { - t.Fatal(fmt.Sprintf("want '%s', but got '%s'", source, db.DataSource())) + 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())) } } func TestDB_CopyIn(t *testing.T) { - source := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=%s password=%s", - "localhost", "postgres", "test", "disable", "123") - db, er := gorm.Open("postgres", source) - if er != nil { - t.Fatal(er.Error()) - } - db.Exec("create table if not exists example(name varchar, age integer)") + DB.Exec("create table if not exists example(name varchar, age integer)") var args = make([][]interface{}, 0) args = append(args, []interface{}{ "tom", 9, @@ -1088,7 +1076,7 @@ func TestDB_CopyIn(t *testing.T) { }, []interface{}{ "jim", 11, }) - e := db.CopyIn(true, "example", args, "name", "age") + e := DB.CopyIn(true, "example", args, "name", "age") if e != nil { t.Fatal(e.Error()) } @@ -1097,7 +1085,7 @@ func TestDB_CopyIn(t *testing.T) { Age int } var examples = make([]Example,0) - e=db.Raw("select * from example").Find(&examples).Error + e=DB.Raw("select * from example").Find(&examples).Error if e!=nil { t.Fatal(e.Error()) }