github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cmd/test.go (about)

     1  // Copyright 2020 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 cmd
    15  
    16  import (
    17  	"fmt"
    18  	"os"
    19  	"strings"
    20  
    21  	"github.com/pingcap/ticdc/cdc/kv"
    22  	"github.com/pingcap/tidb/store/tikv"
    23  	"github.com/spf13/cobra"
    24  	pd "github.com/tikv/pd/client"
    25  )
    26  
    27  var testPdAddr string
    28  
    29  func init() {
    30  	rootCmd.AddCommand(testKVCmd)
    31  
    32  	testKVCmd.Flags().StringVar(&testPdAddr, "pd", "http://127.0.0.1:2379", "address of PD")
    33  }
    34  
    35  type testingT struct {
    36  }
    37  
    38  // Errorf implements require.TestingT
    39  func (t *testingT) Errorf(format string, args ...interface{}) {
    40  	fmt.Printf(format, args...)
    41  }
    42  
    43  // FailNow implements require.TestingT
    44  func (t *testingT) FailNow() {
    45  	os.Exit(-1)
    46  }
    47  
    48  var testKVCmd = &cobra.Command{
    49  	Hidden: true,
    50  	Use:    "testkv",
    51  	Short:  "test kv",
    52  	Long:   ``,
    53  	Run: func(cmd *cobra.Command, args []string) {
    54  		addrs := strings.Split(testPdAddr, ",")
    55  		cli, err := pd.NewClient(addrs, getCredential().PDSecurityOption())
    56  		if err != nil {
    57  			fmt.Println(err)
    58  			return
    59  		}
    60  
    61  		storage, err := kv.CreateStorage(addrs[0])
    62  		if err != nil {
    63  			fmt.Println(err)
    64  			return
    65  		}
    66  
    67  		tikvStorage := storage.(tikv.Storage) // we know it is tikv.
    68  
    69  		t := new(testingT)
    70  		kv.TestGetKVSimple(t, cli, tikvStorage, storage)
    71  		kv.TestSplit(t, cli, tikvStorage, storage)
    72  	},
    73  }