Skip to content

Commit

Permalink
fix executor set unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal authored and systay committed Jul 28, 2020
1 parent 61875d8 commit 404d357
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ func TestExecutorSet(t *testing.T) {
executorEnv, _, _, _ := createExecutorEnv()

testcases := []struct {
in string
out *vtgatepb.Session
err string
target string
in string
out *vtgatepb.Session
err string
}{{
in: "set autocommit = 1",
out: &vtgatepb.Session{Autocommit: true},
Expand Down Expand Up @@ -216,53 +215,18 @@ func TestExecutorSet(t *testing.T) {
}, {
in: "set character set ascii",
err: "unexpected value for charset/names: ascii",
}, {
in: "set net_write_timeout = 600",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set net_read_timeout = 600",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set sql_quote_show_create = 1",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set foreign_key_checks = 0",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set unique_checks = 0",
out: &vtgatepb.Session{Autocommit: true},
}, {
in: "set skip_query_plan_cache = 1",
out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{SkipQueryPlanCache: true}},
}, {
in: "set skip_query_plan_cache = 0",
out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{}},
}, {
in: "set sql_auto_is_null = 0",
target: "TestExecutor",
out: &vtgatepb.Session{Autocommit: true, TargetString: "TestExecutor"},
}, {
in: "set sql_auto_is_null = 1",
target: "TestExecutor",
out: &vtgatepb.Session{Autocommit: true, TargetString: "TestExecutor"},
}, {
in: "set tx_read_only = 2",
err: "unexpected value for tx_read_only: 2",
}, {
in: "set transaction_read_only = 2",
err: "unexpected value for transaction_read_only: 2",
}, {
in: "set tx_isolation = 'invalid'",
err: "unexpected value for tx_isolation: invalid",
}, {
in: "set @foo = 'bar'",
out: &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo"}, []interface{}{"bar"}), Autocommit: true},
}, {
in: "set @foo = 2",
out: &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo"}, []interface{}{2}), Autocommit: true},
}, {
in: "set @foo = 2.1, @bar = 'baz'",
out: &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo", "bar"}, []interface{}{2.1, "baz"}), Autocommit: true},
}, {
in: "set session transaction isolation level repeatable read",
out: &vtgatepb.Session{Autocommit: true},
Expand Down Expand Up @@ -290,9 +254,10 @@ func TestExecutorSet(t *testing.T) {
}}
for _, tcase := range testcases {
t.Run(tcase.in, func(t *testing.T) {
session := NewSafeSession(&vtgatepb.Session{Autocommit: true, TargetString: tcase.target})
session := NewSafeSession(&vtgatepb.Session{Autocommit: true})
_, err := executorEnv.Execute(context.Background(), "TestExecute", session, tcase.in, nil)
if tcase.err == "" {
require.NoError(t, err)
utils.MustMatch(t, tcase.out, session.Session, "new executor")
} else {
require.EqualError(t, err, tcase.err)
Expand All @@ -305,22 +270,43 @@ func TestExecutorSetOp(t *testing.T) {
executor, _, _, sbclookup := createLegacyExecutorEnv()

sbclookup.SetResults([]*sqltypes.Result{
sqltypes.MakeTestResult(sqltypes.MakeTestFields("'STRICT_ALL_TABLES,NO_AUTO_UPDATES'", "varchar"), "STRICT_ALL_TABLES,NO_AUTO_UPDATES"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("1", "int64"), "1"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_mode", "varchar"), "STRICT_ALL_TABLES,NO_AUTO_UPDATES"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_safe_updates", "int64"), "1"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("tx_isolation", "varchar"), "read-committed"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_quote_show_create", "int64"), "0"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("foreign_key_checks", "int64")),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("unique_checks", "int64"), "0"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("net_write_timeout", "int64"), "600"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("net_read_timeout", "int64"), "300"),
})

testcases := []struct {
in string
warning []*querypb.QueryWarning
sysVars map[string]string
}{{
in: "set big_tables = 1",
in: "set big_tables = 1", //ignore
}, {
in: "set sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_UPDATES'",
sysVars: map[string]string{"sql_mode": "'STRICT_ALL_TABLES,NO_AUTO_UPDATES'"},
}, {
in: "set sql_safe_updates = 1",
sysVars: map[string]string{"sql_safe_updates": "1"},
}, {
in: "set tx_isolation = 'read-committed'",
sysVars: map[string]string{"tx_isolation": "'read-committed'"},
}, {
in: "set sql_quote_show_create = 0",
sysVars: map[string]string{"sql_quote_show_create": "0"},
}, {
in: "set foreign_key_checks = 1",
}, {
in: "set unique_checks = 0",
sysVars: map[string]string{"unique_checks": "0"},
}, {
in: "set net_write_timeout = 600",
}, {
in: "set net_read_timeout = 600",
}}
for _, tcase := range testcases {
t.Run(tcase.in, func(t *testing.T) {
Expand Down

0 comments on commit 404d357

Please sign in to comment.