-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_test.go
43 lines (36 loc) · 919 Bytes
/
db_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDB_SuccessfulConnection1(t *testing.T) {
dbPath := "_test.db"
_, err := NewDB(dbPath)
assert.NoError(t, err)
// Add this defer function to remove the database file after test
defer func() {
err := os.Remove(dbPath)
if err != nil {
t.Fatal(err)
}
}()
}
func TestNewDB_SuccessfulConnection2(t *testing.T) {
dbURI := "sqlite3://:memory:"
db, err := NewDB(dbURI)
assert.NoError(t, err)
assert.NotNil(t, db)
}
func TestNewDB_InvalidURI(t *testing.T) {
dbURI := "invalid_uri"
_, err := NewDB(dbURI)
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to parse database URL")
}
func TestNewDB_UnsupportedDriver(t *testing.T) {
dbURI := "sqlserver://user:pass@remote-host.com/dbname"
_, err := NewDB(dbURI)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unsupported database driver")
}