Skip to content

Commit

Permalink
added sample test data for filter_cases e2e testing
Browse files Browse the repository at this point in the history
Signed-off-by: c-r-dev <[email protected]>
  • Loading branch information
c-r-dev committed Dec 17, 2024
1 parent b99ebab commit 1400fea
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
26 changes: 26 additions & 0 deletions go/test/endtoend/vtgate/plan_tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/utils"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtgate/engine"
"vitess.io/vitess/go/vt/vtgate/planbuilder"
)
Expand Down Expand Up @@ -128,6 +129,31 @@ func start(t *testing.T) (utils.MySQLCompare, func()) {
}
}

// parseSQL statements - querySQL may be a multi-line sql blob
func parseSQL(querySQL ...string) ([]string, error) {
parser := sqlparser.NewTestParser()
var sqls []string
for _, sql := range querySQL {
split, err := parser.SplitStatementToPieces(sql)
if err != nil {
return nil, err
}
sqls = append(sqls, split...)
}
return sqls, nil
}

func loadSampleData(t *testing.T, mcmp utils.MySQLCompare) {
sampleDataSQL := readFile("sampledata/user.sql")
insertSQL, err := parseSQL(sampleDataSQL)
if err != nil {
require.NoError(t, err)
}
for _, sql := range insertSQL {
mcmp.ExecNoCompare(sql)
}
}

func readJSONTests(filename string) []planbuilder.PlanTest {
var output []planbuilder.PlanTest
file, err := os.Open(locateFile(filename))
Expand Down
1 change: 1 addition & 0 deletions go/test/endtoend/vtgate/plan_tests/plan_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestSelectCases(t *testing.T) {
func TestFilterCases(t *testing.T) {
mcmp, closer := start(t)
defer closer()
loadSampleData(t, mcmp)
tests := readJSONTests("filter_cases.json")
for _, test := range tests {
mcmp.Run(test.Comment, func(mcmp *utils.MySQLCompare) {
Expand Down
3 changes: 1 addition & 2 deletions go/vt/vtgate/planbuilder/testdata/filter_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -5109,7 +5109,6 @@
"user.sales",
"user.sales_extra"
]
},
"skip_e2e":true
}
}
]
14 changes: 14 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/sampledata/user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSERT INTO sales (oid, col1)
VALUES (1, 'a_1');

INSERT INTO sales_extra(colx, cola, colb, start, end)
VALUES (11, 'a_1', 'b_1',0, 500);

INSERT INTO sales_extra(colx, cola, colb, start, end)
VALUES (12, 'a_2', 'b_2',500, 1000);

INSERT INTO sales_extra(colx, cola, colb, start, end)
VALUES (13, 'a_3', 'b_3',1000, 1500);

INSERT INTO sales_extra(colx, cola, colb, start, end)
VALUES (14, 'a_4', 'b_4',1500, 2000);

0 comments on commit 1400fea

Please sign in to comment.