From 2445b0ee54e50292d4c6519085d9958247ba06c8 Mon Sep 17 00:00:00 2001 From: fwhez <1728565484@qq.com> Date: Mon, 12 Nov 2018 10:10:31 +0800 Subject: [PATCH] * put testcase into main_test.go --- main_copyIn_test.go | 49 --------------------------------------------- main_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 main_copyIn_test.go diff --git a/main_copyIn_test.go b/main_copyIn_test.go deleted file mode 100644 index 372ae299..00000000 --- a/main_copyIn_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package gorm - -import ( - "fmt" - "github.com/fwhezfwhez/gorm" - "testing" - -) - -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 := Open("postgres", source) - if er != nil { - t.Fatal(er.Error()) - } - fmt.Println(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)") - var args = make([][]interface{}, 0) - args = append(args, []interface{}{ - "tom", 9, - }, []interface{}{ - "sara", 10, - }, []interface{}{ - "jim", 11, - }) - e := db.CopyIn(true, "example", args, "name", "age") - if e != nil { - t.Fatal(e.Error()) - } - type Example struct{ - Name string - Age int - } - var examples = make([]Example,0) - e=db.Raw("select * from example").Find(&examples).Error - if e!=nil { - t.Fatal(e.Error()) - } - fmt.Println(examples) -} diff --git a/main_test.go b/main_test.go index 94d2fa39..ab614254 100644 --- a/main_test.go +++ b/main_test.go @@ -1059,6 +1059,55 @@ 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())) + } + +} +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)") + var args = make([][]interface{}, 0) + args = append(args, []interface{}{ + "tom", 9, + }, []interface{}{ + "sara", 10, + }, []interface{}{ + "jim", 11, + }) + e := db.CopyIn(true, "example", args, "name", "age") + if e != nil { + t.Fatal(e.Error()) + } + type Example struct{ + Name string + Age int + } + var examples = make([]Example,0) + e=db.Raw("select * from example").Find(&examples).Error + if e!=nil { + t.Fatal(e.Error()) + } + if len(examples) ==0 { + t.Fatal("examples length wants more than 3, but got 0") + } + fmt.Println(examples) +} + + func BenchmarkGorm(b *testing.B) { b.N = 2000 for x := 0; x < b.N; x++ {