From deabaa67af1d9987244273c1344b840024d0fa94 Mon Sep 17 00:00:00 2001 From: taherkl Date: Fri, 20 Dec 2024 14:48:58 +0530 Subject: [PATCH] Fixed UT --- sources/mysql/infoschema_test.go | 52 -------------------------------- 1 file changed, 52 deletions(-) diff --git a/sources/mysql/infoschema_test.go b/sources/mysql/infoschema_test.go index 088c1b5ea..987a9b4a3 100644 --- a/sources/mysql/infoschema_test.go +++ b/sources/mysql/infoschema_test.go @@ -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) -}