Skip to content

Commit 93b7dd3

Browse files
authored
Merge pull request #55 from gliptak/drivertest1
Tests for driver DSN
2 parents 600aa16 + 2a46c55 commit 93b7dd3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

driver_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
7575
t.Errorf("expected no error, but got: %s", err)
7676
}
7777
db2, mock2, err := New()
78+
if err != nil {
79+
t.Errorf("expected no error, but got: %s", err)
80+
}
7881
if len(pool.conns) != 2 {
7982
t.Errorf("expected 2 connection in pool, but there is: %d", len(pool.conns))
8083
}
@@ -86,3 +89,24 @@ func TestTwoOpenConnectionsOnTheSameDSN(t *testing.T) {
8689
t.Errorf("expected not the same mock instance, but it is the same")
8790
}
8891
}
92+
93+
func TestWrongDSN(t *testing.T) {
94+
t.Parallel()
95+
db, _, _ := New()
96+
defer db.Close()
97+
if _, err := db.Driver().Open("wrong_dsn"); err == nil {
98+
t.Error("expected error on Open")
99+
}
100+
}
101+
102+
func TestNewDSN(t *testing.T) {
103+
if _, _, err := NewWithDSN("sqlmock_db_99"); err != nil {
104+
t.Errorf("expected no error on NewWithDSN, but got: %s", err)
105+
}
106+
}
107+
108+
func TestDuplicateNewDSN(t *testing.T) {
109+
if _, _, err := NewWithDSN("sqlmock_db_1"); err == nil {
110+
t.Error("expected error on NewWithDSN")
111+
}
112+
}

0 commit comments

Comments
 (0)