Skip to content

Commit

Permalink
Fixed UT
Browse files Browse the repository at this point in the history
  • Loading branch information
taherkl committed Dec 20, 2024
1 parent 0fb39e4 commit deabaa6
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions sources/mysql/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,55 +680,3 @@ func TestGetConstraints_CheckConstraintsTableAbsent(t *testing.T) {
_, _, _, err := isi.GetConstraints(conv, common.SchemaAndName{Schema: "your_schema", Name: "your_table"})
assert.Error(t, err)
}

func TestGetConstraints(t *testing.T) {

case1 := []mockSpec{
{
query: `SELECT COUNT\(\*\) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'INFORMATION_SCHEMA' AND TABLE_NAME = 'CHECK_CONSTRAINTS';`,
cols: []string{"COUNT(*)"},
rows: [][]driver.Value{{1}},
},
{
query: `SELECT k.COLUMN_NAME, t.CONSTRAINT_TYPE, COALESCE\(c.CHECK_CLAUSE, ''\) AS CHECK_CLAUSE
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON t.CONSTRAINT_NAME = k.CONSTRAINT_NAME
AND t.CONSTRAINT_SCHEMA = k.CONSTRAINT_SCHEMA
AND t.TABLE_NAME = k.TABLE_NAME
LEFT JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS AS c
ON t.CONSTRAINT_NAME = c.CONSTRAINT_NAME
WHERE t.TABLE_SCHEMA = \?
AND t.TABLE_NAME = \?
ORDER BY k.ORDINAL_POSITION;`,
args: []driver.Value{"your_schema", "your_table"},
cols: []string{"COLUMN_NAME", "CONSTRAINT_TYPE", "CHECK_CLAUSE"},
rows: [][]driver.Value{{"column1", "PRIMARY KEY", ""}, {"column2", "CHECK", "(column2 > 0)"}},
},
}
db := mkMockDB(t, ms)
isi := InfoSchemaImpl{Db: db}
conv := &internal.Conv{}

primaryKeys, checkKeys, m, err := isi.GetConstraints(conv, common.SchemaAndName{Schema: "your_schema", Name: "your_table"})
assert.NoError(t, err)
assert.Equal(t, []string{"column1"}, primaryKeys)
assert.Equal(t, []schema.CheckConstraint{{Name: "column2_check", Expr: "(column2 > 0)", Id: "cc1"}}, checkKeys) // Modify according to actual struct
assert.NotNil(t, m) // Modify according to expected map behavior
}

func TestGetConstraints_CheckConstraintsTableAbsent(t *testing.T) {
ms := []mockSpec{
{
query: `SELECT COUNT\(\*\) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'INFORMATION_SCHEMA' AND TABLE_NAME = 'CHECK_CONSTRAINTS';`,
cols: []string{"COUNT(*)"},
rows: [][]driver.Value{{0}},
},
}
db := mkMockDB(t, ms)
isi := InfoSchemaImpl{Db: db}
conv := &internal.Conv{}

_, _, _, err := isi.GetConstraints(conv, common.SchemaAndName{Schema: "your_schema", Name: "your_table"})
assert.Error(t, err)
}

0 comments on commit deabaa6

Please sign in to comment.