github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/meta/internal/registry_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 internal
    15  
    16  import (
    17  	"testing"
    18  
    19  	metaModel "github.com/pingcap/tiflow/engine/pkg/meta/model"
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  type duplicatedClientBuilder struct{}
    24  
    25  func (b *duplicatedClientBuilder) ClientType() metaModel.ClientType {
    26  	return metaModel.EtcdKVClientType
    27  }
    28  
    29  func (b *duplicatedClientBuilder) NewKVClientWithNamespace(cc metaModel.ClientConn,
    30  	projectID metaModel.ProjectID, jobID metaModel.JobID,
    31  ) (metaModel.KVClient, error) {
    32  	return nil, nil
    33  }
    34  
    35  func TestMustRegisterClientBuilder(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	r := GlobalClientBuilderRegistra()
    39  	require.Len(t, r.reg, 3)
    40  
    41  	defer func() {
    42  		err := recover()
    43  		require.NotNil(t, err)
    44  		require.Regexp(t, "client type is already existed", err.(string))
    45  	}()
    46  
    47  	MustRegisterClientBuilder(&duplicatedClientBuilder{})
    48  }
    49  
    50  func TestGetClientBuilder(t *testing.T) {
    51  	t.Parallel()
    52  
    53  	_, err := GetClientBuilder(metaModel.MockKVClientType)
    54  	require.NoError(t, err)
    55  
    56  	_, err = GetClientBuilder(metaModel.EtcdKVClientType)
    57  	require.NoError(t, err)
    58  
    59  	_, err = GetClientBuilder(metaModel.SQLKVClientType)
    60  	require.NoError(t, err)
    61  }