/
mysqlMgr_test.go
65 lines (60 loc) · 1.81 KB
/
mysqlMgr_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mysqlMgr
import (
"database/sql"
"testing"
)
//TestStmtExists test the helper function for existing statements
func TestStmtExists(t *testing.T) {
testStore := store{}
testStore.stmtMap = make(map[string]*sql.Stmt)
testStore.stmtMap["test_query"] = nil
if !testStore.stmtExists("test_query") {
t.Fatal("stmtExists returned incorrect value")
}
}
//TestConString checks if the connection string is being properly generated
func TestConString(t *testing.T) {
sample := config{Database: "test", Server: "test", User: "test", Pw: "test"}
e := sample.genConStr()
if e != nil {
t.Fatal("Test Con String was invalid:")
}
}
//TestDefaults checks if the defaults are correctly applied to the configuration
func TestDefaults(t *testing.T) {
sample := config{Database: "test", Server: "test", User: "test", Pw: "test"}
e := sample.genConStr()
if e != nil {
t.Fatalf("Default port conn str returned: %s", e)
}
if sample.Port != "3306" {
t.Fatal("Default port not set with empty port in config")
}
if sample.Driver != "mysql" {
t.Fatal("Default driver not set with empty driver in config")
}
}
//TestMissingConfigValues ensures that the inspection of the configuration
//returns the proper errors for missing values
func TestMissingConfigValues(t *testing.T) {
sample := config{}
e := sample.genConStr()
if e == nil {
t.Fatal("Missing User Value should have returned error, returned nil")
}
sample.User = "test"
e = sample.genConStr()
if e == nil {
t.Fatal("Missing Server Value should have returned error, returned nil")
}
sample.Server = "test"
e = sample.genConStr()
if e == nil {
t.Fatal("Missing Database Value should have returned error, returned nil")
}
sample.Database = "test"
e = sample.genConStr()
if e != nil {
t.Fatal("Minimum configuration should have returned nil, returned error")
}
}