Tidying up tests

This commit is contained in:
Jason Fulghum
2023-05-22 13:03:00 -07:00
parent 82014da2fc
commit 55eab2d7d4
2 changed files with 102 additions and 70 deletions

View File

@@ -219,6 +219,13 @@ func (itr prollyCVIter) Next(ctx *sql.Context) (sql.Row, error) {
return nil, err
}
r[o] = m
case prolly.ArtifactTypeChkConsViol:
var m merge.CheckCVMeta
err = json.Unmarshal(meta.VInfo, &m)
if err != nil {
return nil, err
}
r[o] = m
default:
panic("json not implemented for artifact type")
}

View File

@@ -4118,7 +4118,7 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
// Constraint changes
// Constraints: Not Null
{
Name: "removing a not-null constraint",
AncSetUpScript: []string{
@@ -4150,6 +4150,8 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
},
// Constraints: Foreign Keys
{
Name: "adding a foreign key to one side, with fk constraint violation",
AncSetUpScript: []string{
@@ -4216,6 +4218,8 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
},
// Constraints: Unique
{
Name: "adding a unique key, with unique key violation",
AncSetUpScript: []string{
@@ -4290,75 +4294,6 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
},
// TODO: Another case to test is when a constraint is added on one side, but the other side adds
// data that would violate the constraint
{
Name: "check constraint violation - simple case, no schema changes",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 int, col2 int, CHECK (col1 != col2));",
"INSERT into t values (1, 2, 3);",
"alter table t add index idx1 (pk, col2);",
},
RightSetUpScript: []string{
"update t set col2=4;",
},
LeftSetUpScript: []string{
"update t set col1=4;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
},
},
{
Name: "check constraint violation - schema change",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 int, col2 int, col3 int, CHECK (col2 != col3));",
"INSERT into t values (1, 2, 3, -3);",
"alter table t add index idx1 (pk, col2);",
},
RightSetUpScript: []string{
"update t set col2=100;",
},
LeftSetUpScript: []string{
"alter table t drop column col1;",
"update t set col3=100;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
},
},
{
Name: "check constraint violation - left side violates new check constraint",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 varchar(100));",
"INSERT into t values (1, 'hi');",
"alter table t add index idx1 (col1);",
},
RightSetUpScript: []string{
"alter table t add constraint CHECK (col1 != concat('he', 'llo'))",
},
LeftSetUpScript: []string{
"insert into t values (2, 'hello');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
// TODO: Look in the constraint violations metadata table
},
},
{
Name: "dropping a unique key",
AncSetUpScript: []string{
@@ -4386,6 +4321,96 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
// Constraints: Check Expressions
{
Name: "check constraint violation - simple case, no schema changes",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 int, col2 int, CHECK (col1 != col2));",
"INSERT into t values (1, 2, 3);",
"alter table t add index idx1 (pk, col2);",
},
RightSetUpScript: []string{
"update t set col2=4;",
},
LeftSetUpScript: []string{
"update t set col1=4;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
{
Query: "select * from dolt_constraint_violations;",
Expected: []sql.Row{{"t", uint64(1)}},
},
{
Query: "select violation_type, pk, col1, col2, violation_info like '\\%NOT((col1 = col2))\\%' from dolt_constraint_violations_t;",
Expected: []sql.Row{{uint64(3), 1, 4, 4, true}},
},
},
},
{
Name: "check constraint violation - schema change",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 int, col2 int, col3 int, CHECK (col2 != col3));",
"INSERT into t values (1, 2, 3, -3);",
"alter table t add index idx1 (pk, col2);",
},
RightSetUpScript: []string{
"update t set col2=100;",
},
LeftSetUpScript: []string{
"alter table t drop column col1;",
"update t set col3=100;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
{
Query: "select * from dolt_constraint_violations;",
Expected: []sql.Row{{"t", uint64(1)}},
},
{
Query: "select violation_type, pk, col2, col3, violation_info like '\\%NOT((col2 = col3))\\%' from dolt_constraint_violations_t;",
Expected: []sql.Row{{uint64(3), 1, 100, 100, true}},
},
},
},
{
Name: "check constraint violation - left side violates new check constraint",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 varchar(100));",
"INSERT into t values (1, 'hi');",
"alter table t add index idx1 (col1);",
},
RightSetUpScript: []string{
"alter table t add constraint CHECK (col1 != concat('he', 'llo'))",
},
LeftSetUpScript: []string{
"insert into t values (2, 'hello');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
{
Query: "select * from dolt_constraint_violations;",
Expected: []sql.Row{{"t", uint64(1)}},
},
{
Query: `select violation_type, pk, col1, violation_info like "\%NOT((col1 = concat('he','llo')))\%" from dolt_constraint_violations_t;`,
Expected: []sql.Row{{uint64(3), 2, "hello", true}},
},
},
},
// Resolvable type changes
{
Name: "type widening - enums and sets",