-
Notifications
You must be signed in to change notification settings - Fork 125
/
sql_mapper_test.go
42 lines (34 loc) · 1018 Bytes
/
sql_mapper_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
package geo
import (
"database/sql"
"fmt"
"os"
"testing"
)
// Ensures that creating a new SQL Mapper does not encounter an error upon initialization
// And also matches the expected database connections and sql configurations.
func TestNewSQLMapper(t *testing.T) {
conf := sqlConfFromEnv()
db, _ := sql.Open(conf.driver, conf.openStr)
env := os.Getenv("DB")
filepath := fmt.Sprintf("db/%s/dbconf.yml", env)
s, _ := NewSQLMapper(filepath, db)
if s == nil {
t.Error("Expected NewSqlMapper to return a non-nil pointer to a sql mapper")
}
if s.sqlConn != db {
t.Error()
}
}
// Ensures that creating a new SQLMapper and getting its SQL DB Connection
// is the same *sql.DB used in initialization.
func TestSqlDbConn(t *testing.T) {
conf := sqlConfFromEnv()
db, _ := sql.Open(conf.driver, conf.openStr)
env := os.Getenv("DB")
filepath := fmt.Sprintf("db/%s/dbconf.yml", env)
s, _ := NewSQLMapper(filepath, db)
if s.SqlDbConn() != db {
t.Error("Expected db connections are mismatched.")
}
}