-
Notifications
You must be signed in to change notification settings - Fork 1
/
e2e_test.go
77 lines (70 loc) · 1.88 KB
/
e2e_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
package bqin_test
import (
"context"
"reflect"
"testing"
"github.com/kayac/bqin"
"github.com/kayac/bqin/internal/logger"
"github.com/kylelemons/godebug/pretty"
)
func TestE2E(t *testing.T) {
cases := []struct {
CaseName string
Configure string
Messages []string
Expected map[string][]string
}{
{
CaseName: "default",
Configure: "testdata/config/standard.yaml",
Messages: []string{
"testdata/sqs/user.json",
},
Expected: map[string][]string{
"bqin-test-gcp.test.user": []string{
"gs://bqin-import-tmp/data/user/snapshot_at=20200210/part-0001.csv",
},
},
},
{
CaseName: "hive_format_rule",
Configure: "testdata/config/hive_format.yaml",
Messages: []string{
"testdata/sqs/user.json",
},
Expected: map[string][]string{
"bqin-test-gcp.test.user_20200210": []string{
"gs://bqin-import-tmp/data/user/snapshot_at=20200210/part-0001.csv",
},
},
},
}
for _, c := range cases {
t.Run(c.CaseName, func(t *testing.T) {
logger.Setup(logger.NewTestingLogWriter(t), GetLogLevel())
mgr := NewStubManager("testdata/s3/")
defer mgr.Close()
t.Log(c.Messages)
if err := mgr.SQS.SendMessagesFromFile(c.Messages); err != nil {
t.Fatalf("Prepare failed, load message body %s:", err)
}
conf, err := bqin.LoadConfig(c.Configure)
if err != nil {
t.Fatalf("Prepare failed, load configure %s:", err)
}
mgr.OverwriteConfig(conf)
app := bqin.NewApp(conf)
runOpts := []bqin.RunOption{
bqin.WithExitNoMessage(true),
bqin.WithExitError(true),
}
if err = app.Run(context.Background(), runOpts...); err != nil && err != bqin.ErrNoMessage {
t.Fatalf("unexpected run error: %s", err)
}
loaded := mgr.BigQuery.LoadedData()
if !reflect.DeepEqual(loaded, c.Expected) {
t.Errorf("bigquery loaded data status unexpected: %s", pretty.Compare(loaded, c.Expected))
}
})
}
}