~vtuson/scopecreator/twitter-template

« back to all changes in this revision

Viewing changes to src/go/src/github.com/kellydunn/golang-geo/sql_mapper_test.go

  • Committer: Victor Palau
  • Date: 2015-03-11 14:24:42 UTC
  • Revision ID: vtuson@gmail.com-20150311142442-f2pxp111c8ynv232
public release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package geo
 
2
 
 
3
import (
 
4
        "database/sql"
 
5
        "fmt"
 
6
        "os"
 
7
        "testing"
 
8
)
 
9
 
 
10
// Ensures that creating a new SQL Mapper does not encounter an error upon initialization
 
11
// And also matches the expected database connections and sql configurations.
 
12
func TestNewSQLMapper(t *testing.T) {
 
13
        conf := sqlConfFromEnv()
 
14
        db, _ := sql.Open(conf.driver, conf.openStr)
 
15
 
 
16
        env := os.Getenv("DB")
 
17
        filepath := fmt.Sprintf("db/%s/dbconf.yml", env)
 
18
        s, _ := NewSQLMapper(filepath, db)
 
19
 
 
20
        if s == nil {
 
21
                t.Error("Expected NewSqlMapper to return a non-nil pointer to a sql mapper")
 
22
        }
 
23
 
 
24
        if s.sqlConn != db {
 
25
                t.Error()
 
26
        }
 
27
}
 
28
 
 
29
// Ensures that creating a new SQLMapper and getting its SQL DB Connection
 
30
// is the same *sql.DB used in initialization.
 
31
func TestSqlDbConn(t *testing.T) {
 
32
        conf := sqlConfFromEnv()
 
33
        db, _ := sql.Open(conf.driver, conf.openStr)
 
34
 
 
35
        env := os.Getenv("DB")
 
36
        filepath := fmt.Sprintf("db/%s/dbconf.yml", env)
 
37
        s, _ := NewSQLMapper(filepath, db)
 
38
 
 
39
        if s.SqlDbConn() != db {
 
40
                t.Error("Expected db connections are mismatched.")
 
41
        }
 
42
}