forked from fujiwara/Rin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
72 lines (66 loc) · 1.87 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
66
67
68
69
70
71
72
package rin_test
import (
"testing"
rin "github.com/fujiwara/Rin"
)
var BrokenConfig = []string{
"test/config.yml.invalid_regexp",
"test/config.yml.no_key_matcher",
"test/config.yml.not_found",
}
var Excepted = [][]string{
[]string{
"test.bucket.test",
"test/foo/xxx.json",
`/* Rin */ COPY "foo" FROM 's3://test.bucket.test/test/foo/xxx.json' CREDENTIALS 'aws_access_key_id=AAA;aws_secret_access_key=SSS' REGION 'ap-northeast-1' JSON 'auto' GZIP`,
},
[]string{
"test.bucket.test",
"test/bar/y's.csv",
`/* Rin */ COPY "xxx"."bar" FROM 's3://test.bucket.test/test/bar/y''s.csv' CREDENTIALS 'aws_access_key_id=AAA;aws_secret_access_key=SSS' REGION 'ap-northeast-1' CSV DELIMITER ',' ESCAPE`,
},
[]string{
"example.bucket",
"test/s1/t256/aaa.json",
`/* Rin */ COPY "s1"."t256" FROM 's3://example.bucket/test/s1/t256/aaa.json' CREDENTIALS 'aws_access_key_id=AAA;aws_secret_access_key=SSS' REGION 'ap-northeast-1' JSON 'auto' GZIP`,
},
}
func TestLoadConfigError(t *testing.T) {
for _, f := range BrokenConfig {
_, err := rin.LoadConfig(f)
if err == nil {
t.Errorf("LoadConfig(%s) must be failed", f)
}
t.Log(err)
}
}
func TestLoadConfig(t *testing.T) {
config, err := rin.LoadConfig("test/config.yml")
if err != nil {
t.Fatalf("load config failed: %s", err)
}
for _, target := range config.Targets {
t.Log("target:", target)
}
t.Log("global.sql_option", config.SQLOption)
if len(config.Targets) != 3 {
t.Error("invalid targets len", len(config.Targets))
}
for i, target := range config.Targets {
e := Excepted[i]
bucket := e[0]
key := e[1]
ok, cap := target.Match(bucket, key)
if !ok {
t.Errorf("%s %s is not match target: %s", bucket, key, target)
}
sql, err := target.BuildCopySQL(key, config.Credentials, cap)
if err != nil {
t.Error(err)
}
if sql != e[2] {
t.Errorf("unexpected SQL:\n%s\n%s", sql, e[2])
}
t.Log(sql)
}
}