-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codec: Add test for column selector and open codec (#268)
- Loading branch information
1 parent
f5aa01f
commit 2f15b9e
Showing
7 changed files
with
443 additions
and
172 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
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
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,169 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/tiflow/pkg/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewColumnSelector(t *testing.T) { | ||
// the column selector is not set | ||
replicaConfig := config.GetDefaultReplicaConfig() | ||
selectors, err := New(replicaConfig) | ||
require.NoError(t, err) | ||
require.NotNil(t, selectors) | ||
require.Len(t, selectors.selectors, 0) | ||
|
||
replicaConfig.Sink.ColumnSelectors = []*config.ColumnSelector{ | ||
{ | ||
Matcher: []string{"test.*"}, | ||
Columns: []string{"a", "b"}, | ||
}, | ||
{ | ||
Matcher: []string{"test1.*"}, | ||
Columns: []string{"*", "!a"}, | ||
}, | ||
{ | ||
Matcher: []string{"test2.*"}, | ||
Columns: []string{"co*", "!col2"}, | ||
}, | ||
{ | ||
Matcher: []string{"test3.*"}, | ||
Columns: []string{"co?1"}, | ||
}, | ||
} | ||
selectors, err = New(replicaConfig) | ||
require.NoError(t, err) | ||
require.Len(t, selectors.selectors, 4) | ||
} | ||
|
||
func TestColumnSelectorGetSelector(t *testing.T) { | ||
replicaConfig := config.GetDefaultReplicaConfig() | ||
replicaConfig.Sink.ColumnSelectors = []*config.ColumnSelector{ | ||
{ | ||
Matcher: []string{"test.*"}, | ||
Columns: []string{"a", "b"}, | ||
}, | ||
{ | ||
Matcher: []string{"test1.*"}, | ||
Columns: []string{"*", "!a"}, | ||
}, | ||
{ | ||
Matcher: []string{"test2.*"}, | ||
Columns: []string{"co*", "!col2"}, | ||
}, | ||
{ | ||
Matcher: []string{"test3.*"}, | ||
Columns: []string{"co?1"}, | ||
}, | ||
} | ||
selectors, err := New(replicaConfig) | ||
require.NoError(t, err) | ||
|
||
{ | ||
selector := selectors.GetSelector("test", "t1") | ||
tableInfo1 := BuildTableInfo("test", "t1", []*Column{ | ||
{ | ||
Name: "a", | ||
}, | ||
{ | ||
Name: "b", | ||
}, | ||
{ | ||
Name: "c", | ||
}, | ||
}, nil) | ||
for _, col := range tableInfo1.Columns { | ||
if col.Name.O != "c" { | ||
require.True(t, selector.Select(col)) | ||
} else { | ||
require.False(t, selector.Select(col)) | ||
} | ||
} | ||
} | ||
|
||
{ | ||
selector := selectors.GetSelector("test1", "aaa") | ||
tableInfo1 := BuildTableInfo("test1", "aaa", []*Column{ | ||
{ | ||
Name: "a", | ||
}, | ||
{ | ||
Name: "b", | ||
}, | ||
{ | ||
Name: "c", | ||
}, | ||
}, nil) | ||
for _, col := range tableInfo1.Columns { | ||
if col.Name.O != "a" { | ||
require.True(t, selector.Select(col)) | ||
} else { | ||
require.False(t, selector.Select(col)) | ||
} | ||
} | ||
} | ||
|
||
{ | ||
selector := selectors.GetSelector("test2", "t2") | ||
tableInfo1 := BuildTableInfo("test2", "t2", []*Column{ | ||
{ | ||
Name: "a", | ||
}, | ||
{ | ||
Name: "col2", | ||
}, | ||
{ | ||
Name: "col1", | ||
}, | ||
}, nil) | ||
for _, col := range tableInfo1.Columns { | ||
if col.Name.O == "col1" { | ||
require.True(t, selector.Select(col)) | ||
} else { | ||
require.False(t, selector.Select(col)) | ||
} | ||
} | ||
} | ||
|
||
{ | ||
selector := selectors.GetSelector("test3", "t3") | ||
tableInfo1 := BuildTableInfo("test3", "t3", []*Column{ | ||
{ | ||
Name: "a", | ||
}, | ||
{ | ||
Name: "col2", | ||
}, | ||
{ | ||
Name: "col1", | ||
}, | ||
}, nil) | ||
for _, col := range tableInfo1.Columns { | ||
if col.Name.O == "col1" { | ||
require.True(t, selector.Select(col)) | ||
} else { | ||
require.False(t, selector.Select(col)) | ||
} | ||
} | ||
} | ||
|
||
{ | ||
selector := selectors.GetSelector("test4", "t4") | ||
tableInfo1 := BuildTableInfo("test4", "t4", []*Column{ | ||
{ | ||
Name: "a", | ||
}, | ||
{ | ||
Name: "col2", | ||
}, | ||
{ | ||
Name: "col1", | ||
}, | ||
}, nil) | ||
for _, col := range tableInfo1.Columns { | ||
require.True(t, selector.Select(col)) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.