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

     1  // Copyright 2023 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 config
    15  
    16  import (
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/require"
    20  )
    21  
    22  func TestDefaultCDCV2Config(t *testing.T) {
    23  	defaultCDCV2 := defaultServerConfig.Debug.CDCV2
    24  	require.NotNil(t, defaultCDCV2)
    25  	require.False(t, defaultCDCV2.Enable)
    26  }
    27  
    28  func TestCDCV2ValidateAndAdjust(t *testing.T) {
    29  	cdcV2 := &CDCV2{
    30  		Enable:          false,
    31  		MetaStoreConfig: MetaStoreConfiguration{},
    32  	}
    33  	require.Nil(t, cdcV2.ValidateAndAdjust())
    34  	cdcV2.Enable = true
    35  	require.NotNil(t, cdcV2.ValidateAndAdjust())
    36  	cdcV2.MetaStoreConfig.URI = "http://127.0.0.1"
    37  	require.NotNil(t, cdcV2.ValidateAndAdjust())
    38  	cdcV2.MetaStoreConfig.URI = "mysql://127.0.0.1"
    39  	require.Nil(t, cdcV2.ValidateAndAdjust())
    40  }
    41  
    42  func TestGenDSN(t *testing.T) {
    43  	storeConfig := &MetaStoreConfiguration{
    44  		URI: "mysql://root:abcd@127.0.0.1:4000/cdc?a=c&timeout=1m",
    45  	}
    46  	dsn, err := storeConfig.GenDSN()
    47  	require.Nil(t, err)
    48  	require.Equal(t, "root", dsn.User)
    49  	require.Equal(t, "abcd", dsn.Passwd)
    50  	require.Equal(t, "127.0.0.1:4000", dsn.Addr)
    51  	require.Equal(t, "cdc", dsn.DBName)
    52  	require.Equal(t, "true", dsn.Params["parseTime"])
    53  	require.Equal(t, "1m", dsn.Params["timeout"])
    54  	require.Equal(t, "c", dsn.Params["a"])
    55  }