1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2024-11-24 08:12:13 +02:00

Merge pull request #55 from gliptak/drivertest1

Tests for driver DSN
This commit is contained in:
Gediminas Morkevicius 2016-11-24 09:16:41 +02:00 committed by GitHub
commit 93b7dd3ffa

View File

@ -75,6 +75,9 @@ func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
t.Errorf("expected no error, but got: %s", err)
}
db2, mock2, err := New()
if err != nil {
t.Errorf("expected no error, but got: %s", err)
}
if len(pool.conns) != 2 {
t.Errorf("expected 2 connection in pool, but there is: %d", len(pool.conns))
}
@ -86,3 +89,24 @@ func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
t.Errorf("expected not the same mock instance, but it is the same")
}
}
func TestWrongDSN(t *testing.T) {
t.Parallel()
db, _, _ := New()
defer db.Close()
if _, err := db.Driver().Open("wrong_dsn"); err == nil {
t.Error("expected error on Open")
}
}
func TestNewDSN(t *testing.T) {
if _, _, err := NewWithDSN("sqlmock_db_99"); err != nil {
t.Errorf("expected no error on NewWithDSN, but got: %s", err)
}
}
func TestDuplicateNewDSN(t *testing.T) {
if _, _, err := NewWithDSN("sqlmock_db_1"); err == nil {
t.Error("expected error on NewWithDSN")
}
}