-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonoff_patchwork_test.go
70 lines (57 loc) · 3.45 KB
/
onoff_patchwork_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
package sqlpatchwork
import (
"testing"
)
func Test_E2E_OnOffPatchwork(t *testing.T) {
_, err := NewOnOffPatchwork("./test/nothing")
if err == nil {
t.Errorf("Error should be occurrd.")
}
spw, err := NewOnOffPatchwork("./test/onoff_patchwork_test.sql")
if err != nil {
t.Errorf("Error should not be occurrd.")
}
spw.AddQueryPiecesToBuild("itemTypeNotNil")
var expected string
expected = "SELECT s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s INNER JOIN item_master i ON i.item_code = s.item_code WHERE 1=1 AND i.item_type = :item_type GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQuery() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQuery())
}
expected = "SELECT /* ./test/onoff_patchwork_test.sql [__default itemTypeNotNil] */ s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s INNER JOIN item_master i ON i.item_code = s.item_code WHERE 1=1 AND i.item_type = :item_type GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQueryWithTraceDesc() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQueryWithTraceDesc())
}
spw, err = NewOnOffPatchwork("./test/onoff_patchwork_test.sql")
if err != nil {
t.Errorf("Error should not be occurrd.")
}
expected = "SELECT s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s WHERE 1=1 GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQuery() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQuery())
}
}
func Test_E2E_NewOnOffPWSkipPrs(t *testing.T) {
qps := OnOffQPs(
OnOffQP("SELECT s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s"),
OnOffQP("INNER JOIN item_master i ON i.item_code = s.item_code", "itemTypeNotNil", "colorCodeNotNil"),
OnOffQP("WHERE 1=1"),
OnOffQP("AND i.item_type = :item_type", "itemTypeNotNil"),
OnOffQP("AND i.color_code = :color_code", "colorCodeNotNil"),
OnOffQP("GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"))
spw := NewOnOffPWSkipPrs("skipPrsTest", qps)
spw.AddQueryPiecesToBuild("itemTypeNotNil")
var expected string
expected = "SELECT s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s INNER JOIN item_master i ON i.item_code = s.item_code WHERE 1=1 AND i.item_type = :item_type GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQuery() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQuery())
}
expected = "SELECT /* skipPrsTest [__default itemTypeNotNil] */ s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s INNER JOIN item_master i ON i.item_code = s.item_code WHERE 1=1 AND i.item_type = :item_type GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQueryWithTraceDesc() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQueryWithTraceDesc())
}
spw = NewOnOffPWSkipPrs("skipPrsTest", qps)
expected = "SELECT s.item_code , s.sales_date , COUNT(*) AS count FROM sales_tran s WHERE 1=1 GROUP BY s.item_code , s.sales_date ORDER BY s.item_code , s.sales_date"
if spw.BuildQuery() != expected {
t.Errorf("E2E of OnOffPatchwork is failure.\nEXPECTED: %v\nACTUAL : %v", expected, spw.BuildQuery())
}
}