From e7ca6a064e5f7cf743c43fed2841d4782de4725f Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Wed, 18 Dec 2024 11:04:41 -0800 Subject: [PATCH] Clean up. --- sources/mysql/streaming/ddl/ddl_test.go | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sources/mysql/streaming/ddl/ddl_test.go b/sources/mysql/streaming/ddl/ddl_test.go index 7f9e7fa2..e1616583 100644 --- a/sources/mysql/streaming/ddl/ddl_test.go +++ b/sources/mysql/streaming/ddl/ddl_test.go @@ -58,6 +58,44 @@ func TestSchemaAdapter_SQLMode(t *testing.T) { } } +func TestSchemaAdapter_ColumnFiltering(t *testing.T) { + { + // Excluding column [exclude_me] + adapter := NewSchemaAdapter(config.MySQL{Database: "foo", Tables: []*config.MySQLTable{{Name: "test_table", ExcludeColumns: []string{"exclude_me"}}}}, nil) + assert.Equal(t, "foo", adapter.dbName) + + assert.NoError(t, adapter.ApplyDDL(99, "CREATE TABLE test_table (id INT PRIMARY KEY, exclude_me VARCHAR(255));")) + assert.Len(t, adapter.adapters, 1) + + tblAdapter, ok := adapter.GetTableAdapter("test_table") + assert.True(t, ok) + + assert.Len(t, tblAdapter.columns, 2) + + parsedCols, err := tblAdapter.buildParsedColumns() + assert.NoError(t, err) + assert.Len(t, parsedCols, 1) + assert.Equal(t, "id", parsedCols[0].Name) + } + { + // Not excluding + adapter := NewSchemaAdapter(config.MySQL{Database: "foo", Tables: []*config.MySQLTable{{Name: "test_table"}}}, nil) + assert.Equal(t, "foo", adapter.dbName) + + assert.NoError(t, adapter.ApplyDDL(99, "CREATE TABLE test_table (id INT PRIMARY KEY, name VARCHAR(255));")) + assert.Len(t, adapter.adapters, 1) + + tblAdapter, ok := adapter.GetTableAdapter("test_table") + assert.True(t, ok) + + assert.Len(t, tblAdapter.columns, 2) + + parsedCols, err := tblAdapter.buildParsedColumns() + assert.NoError(t, err) + assert.Len(t, parsedCols, 2) + } +} + func TestSchemaAdapter_ApplyDDL(t *testing.T) { { // Column rename