* put testcase into main_test.go

This commit is contained in:
fwhez 2018-11-12 10:10:31 +08:00
parent 0fa79f99d9
commit 2445b0ee54
2 changed files with 49 additions and 49 deletions

View File

@ -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)
}

View File

@ -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) { func BenchmarkGorm(b *testing.B) {
b.N = 2000 b.N = 2000
for x := 0; x < b.N; x++ { for x := 0; x < b.N; x++ {