forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
65 lines (57 loc) · 1.44 KB
/
config_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 pop
import (
"strings"
"testing"
"github.com/gobuffalo/envy"
"github.com/stretchr/testify/require"
)
func Test_LoadsConnectionsFromConfig(t *testing.T) {
r := require.New(t)
r.NoError(LoadConfigFile())
if DialectSupported("sqlite3") {
r.Equal(5, len(Connections))
} else {
r.Equal(4, len(Connections))
}
}
func Test_AddLookupPaths(t *testing.T) {
r := require.New(t)
AddLookupPaths("./foo")
r.Contains(LookupPaths(), "./foo")
}
func Test_ParseConfig(t *testing.T) {
r := require.New(t)
config := strings.NewReader(`
mysql:
dialect: "mysql"
database: "pop_test"
host: "127.0.0.1"
port: "3306"
user: "root"
password: "root"
unsafe: true
options:
readTimeout: 5s`)
conns, err := ParseConfig(config)
r.NoError(err)
r.Equal(1, len(conns))
r.NotNil(conns["mysql"])
r.Equal("mysql", conns["mysql"].Dialect)
r.Equal("pop_test", conns["mysql"].Database)
r.Equal("127.0.0.1", conns["mysql"].Host)
r.Equal("3306", conns["mysql"].Port)
r.Equal(envy.Get("MYSQL_USER", "root"), conns["mysql"].User)
r.Equal(envy.Get("MYSQL_PASSWORD", "root"), conns["mysql"].Password)
r.True(conns["mysql"].Unsafe)
r.Equal("5s", conns["mysql"].Options["readTimeout"])
}
func Test_ParseConfigUnsafeDefault(t *testing.T) {
// Ensure that the default `unsafe` value is false.
r := require.New(t)
config := strings.NewReader(`
mysql:
dialect: "mysql"`)
conns, err := ParseConfig(config)
r.NoError(err)
r.False(conns["mysql"].Unsafe)
}