-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtarget_test.go
135 lines (113 loc) · 4.12 KB
/
target_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"os"
"path"
"testing"
"time"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
)
func TestLoadTargetEmpty(t *testing.T) {
args = Args{target: "testEmpty"}
targetPath := path.Join(args.target, defaultTarget)
extractPath := path.Join(args.target, defaultExtract)
os.Remove(targetPath)
os.Remove(extractPath)
os.Remove(args.target)
err := os.Mkdir(args.target, 0755)
if err != nil {
t.Fatal(err)
}
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()
connections := make(map[string]*Connection)
connectionName := "default"
connections[connectionName] = &Connection{
Driver: "mysql",
db: db,
}
config = Config{Connections: connections}
CreateFile(targetPath, "{}")
extractConfig := "{}"
CreateFile(extractPath, extractConfig)
mock.ExpectPing()
target := loadTarget()
assert.Equal(t, connectionName, target.Connection, "Target Connection set")
assert.Equal(t, defaultExtract, target.Fetch, "Target Fetch set")
assert.Equal(t, []Param(nil), target.Params, "Target Params set")
assert.Equal(t, false, target.Prefetch, "Target Prefetch set")
assert.Equal(t, []*Nest(nil), target.Nest, "Target Prefetch set")
assert.Equal(t, "", target.Script, "Target Script set")
assert.Equal(t, (*Split)(nil), target.Split, "Target Split set")
assert.Equal(t, "", target.Timezone, "Target Timezone set")
assert.Equal(t, connections[connectionName], target.connection, "Target connection set")
assert.Equal(t, extractConfig, target.extract, "Target extract set")
assert.Equal(t, "", target.prefetch, "Target prefetch set")
assert.Equal(t, []interface{}(nil), target.params, "Target params set")
assert.Equal(t, (*time.Location)(nil), target.location, "Target location set")
os.Remove(targetPath)
os.Remove(extractPath)
os.Remove(args.target)
}
func TestLoadTarget(t *testing.T) {
args = Args{target: "testLoad"}
targetPath := path.Join(args.target, defaultTarget)
extractPath := path.Join(args.target, defaultExtract)
prefetchPath := path.Join(args.target, defaultPrefetch)
os.Remove(targetPath)
os.Remove(extractPath)
os.Remove(prefetchPath)
os.Remove(args.target)
err := os.Mkdir(args.target, 0755)
if err != nil {
t.Fatal(err)
}
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()
connections := make(map[string]*Connection)
connectionName := "conn"
connections[connectionName] = &Connection{
Driver: "mysql",
Server: "tcp(mysql-test.ac.uk:4496)",
Database: "test",
// Dsn: "",
Port: 4496,
User: "TESTER",
Password: "PASS",
Timezone: "UTC",
Max: 3,
db: db,
// location: *time.Location,
}
config = Config{Connections: connections}
CreateFile(targetPath, "{\"connection\":\"conn\",\"prefetch\":true}")
extractConfig := "SELECT name, date FROM testTable WHERE id IN (%s)"
CreateFile(extractPath, extractConfig)
prefetchConfig := "SELECT id FROM testTable"
CreateFile(prefetchPath, prefetchConfig)
mock.ExpectPing()
target := loadTarget()
assert.Equal(t, connectionName, target.Connection, "Target Connection set")
assert.Equal(t, defaultExtract, target.Fetch, "Target Fetch set")
assert.Equal(t, []Param(nil), target.Params, "Target Params set")
assert.Equal(t, true, target.Prefetch, "Target Prefetch set")
assert.Equal(t, []*Nest(nil), target.Nest, "Target Nest set")
assert.Equal(t, "", target.Script, "Target Script set")
assert.Equal(t, (*Split)(nil), target.Split, "Target Split set")
assert.Equal(t, "", target.Timezone, "Target Timezone set")
assert.Equal(t, connections[connectionName], target.connection, "Target connection set")
assert.Equal(t, extractConfig, target.extract, "Target extract set")
assert.Equal(t, prefetchConfig, target.prefetch, "Target prefetch set")
assert.Equal(t, []interface{}(nil), target.params, "Target params set")
assert.Equal(t, (*time.Location)(nil), target.location, "Target location set")
os.Remove(targetPath)
os.Remove(extractPath)
os.Remove(prefetchPath)
os.Remove(args.target)
}