github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/filter/utils_test.go (about)

     1  // Copyright 2022 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package filter
    15  
    16  import (
    17  	"testing"
    18  
    19  	tifilter "github.com/pingcap/tidb/pkg/util/filter"
    20  	"github.com/pingcap/tiflow/pkg/config"
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestIsSchema(t *testing.T) {
    25  	t.Parallel()
    26  	cases := []struct {
    27  		schema string
    28  		result bool
    29  	}{
    30  		{"", false},
    31  		{"test", false},
    32  		{"SYS", true},
    33  		{"MYSQL", true},
    34  		{tifilter.InformationSchemaName, true},
    35  		{tifilter.InspectionSchemaName, true},
    36  		{tifilter.PerformanceSchemaName, true},
    37  		{tifilter.MetricSchemaName, true},
    38  		{TiCDCSystemSchema, true},
    39  	}
    40  	for _, c := range cases {
    41  		require.Equal(t, c.result, isSysSchema(c.schema))
    42  	}
    43  }
    44  
    45  func TestVerifyTableRules(t *testing.T) {
    46  	t.Parallel()
    47  	cases := []struct {
    48  		cfg      *config.FilterConfig
    49  		hasError bool
    50  	}{
    51  		{&config.FilterConfig{Rules: []string{""}}, false},
    52  		{&config.FilterConfig{Rules: []string{"*.*"}}, false},
    53  		{&config.FilterConfig{Rules: []string{"test.*ms"}}, false},
    54  		{&config.FilterConfig{Rules: []string{"*.889"}}, false},
    55  		{&config.FilterConfig{Rules: []string{"test-a.*", "*.*.*"}}, true},
    56  		{&config.FilterConfig{Rules: []string{"*.*", "*.*.*", "*.*.*.*"}}, true},
    57  	}
    58  	for _, c := range cases {
    59  		_, err := VerifyTableRules(c.cfg)
    60  		require.Equal(t, c.hasError, err != nil, "case: %s", c.cfg.Rules)
    61  	}
    62  }