github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/client/executor_client_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 client
    15  
    16  import (
    17  	"os"
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/pingcap/tiflow/pkg/security"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestNewExecutorClientNotBlocking(t *testing.T) {
    26  	t.Parallel()
    27  
    28  	factory := newExecutorClientFactory(nil, nil)
    29  
    30  	startTime := time.Now()
    31  	_, _ = factory.NewExecutorClient("invalid:1234")
    32  	require.Less(t, time.Since(startTime), 1*time.Second)
    33  }
    34  
    35  func TestExecutorClientFactoryIllegalCredentials(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	dir := t.TempDir()
    39  	caPath := dir + "/ca.pem"
    40  	err := os.WriteFile(caPath, []byte("invalid ca pem"), 0o600)
    41  	require.NoError(t, err)
    42  
    43  	credentials := &security.Credential{
    44  		CAPath: caPath, // illegal CA path to trigger an error
    45  	}
    46  	factory := newExecutorClientFactory(credentials, nil)
    47  	_, err = factory.NewExecutorClient("127.0.0.1:1234")
    48  	require.Error(t, err)
    49  }