-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add enable_ddl_instant option test (#674)
* test: add enable_ddl_instant option test
- Loading branch information
1 parent
4cffeba
commit 2f06c61
Showing
2 changed files
with
121 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2015 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package session | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hanchuanchuan/goInception/ast" | ||
"github.com/hanchuanchuan/goInception/parser" | ||
"github.com/hanchuanchuan/goInception/sessionctx/variable" | ||
) | ||
|
||
func Test_checkDDLInstantMySQL(t *testing.T) { | ||
parser := parser.New() | ||
sessionVars := variable.NewSessionVars() | ||
parser.SetSQLMode(sessionVars.SQLMode) | ||
|
||
table := &TableInfo{Name: "t1", | ||
Fields: []FieldInfo{ | ||
{Field: "c1", Extra: ""}, | ||
{Field: "c2", Extra: "VIRTUAL"}, | ||
{Field: "c3", Extra: "STORED"}}} | ||
|
||
tests := []struct { | ||
sql string | ||
mysql57 bool | ||
mysql80 bool | ||
}{ | ||
{"alter table t1 add column c1 int;", false, true}, | ||
{"ALTER TABLE t1 ADD COLUMN c2 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL;", true, true}, | ||
{"ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;", false, false}, | ||
{"ALTER TABLE t1 ADD COLUMN c3 INT GENERATED ALWAYS AS (c1 + 1) STORED;", false, false}, | ||
} | ||
|
||
for _, test := range tests { | ||
stmts, _, err := parser.Parse(test.sql, "", "") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
for _, stmtNode := range stmts { | ||
switch node := stmtNode.(type) { | ||
case *ast.AlterTableStmt: | ||
canInstant := checkDDLInstantMySQL57(node) | ||
if canInstant != test.mysql57 { | ||
t.Errorf("canInstant is %v, but excepted %v: sql: %v", canInstant, test.mysql57, test.sql) | ||
} | ||
|
||
canInstant = checkDDLInstantMySQL80(node, table, 80000) | ||
if canInstant != test.mysql80 { | ||
t.Errorf("canInstant is %v, but excepted %v: sql: %v", canInstant, test.mysql57, test.sql) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters