Merge pull request #1210 from baijum/error-zero-args

If no arguments, return error at once
This commit is contained in:
Jinzhu 2016-10-23 22:58:23 +08:00 committed by GitHub
commit c1b9cf186e
2 changed files with 40 additions and 30 deletions

View File

@ -44,7 +44,8 @@ func Open(dialect string, args ...interface{}) (*DB, error) {
if len(args) == 0 {
err = errors.New("invalid database source")
} else {
return nil, err
}
var source string
var dbSQL sqlCommon
@ -79,7 +80,6 @@ func Open(dialect string, args ...interface{}) (*DB, error) {
db.DB().Close()
}
}
}
return &db, err
}

View File

@ -761,6 +761,16 @@ func TestDdlErrors(t *testing.T) {
}
}
func TestOpenWithOneParameter(t *testing.T) {
db, err := gorm.Open("dialect")
if db != nil {
t.Error("Open with one parameter returned non nil for db")
}
if err == nil {
t.Error("Open with one parameter returned err as nil")
}
}
func BenchmarkGorm(b *testing.B) {
b.N = 2000
for x := 0; x < b.N; x++ {