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

     1  // Copyright 2019 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  	"golang.org/x/exp/slices"
    21  )
    22  
    23  func TestCheckingItems(t *testing.T) {
    24  	lightningCheck, normalCheck := 0, 0
    25  	for item := range AllCheckingItems {
    26  		require.NoError(t, ValidateCheckingItem(item))
    27  		if slices.Contains(LightningPrechecks, item) {
    28  			lightningCheck++
    29  		} else {
    30  			normalCheck++
    31  		}
    32  	}
    33  	// remember to update the number when add new checking items.
    34  	require.Equal(t, 6, lightningCheck)
    35  	require.Equal(t, 16, normalCheck)
    36  	// all LightningPrechecks can be found by iterating AllCheckingItems
    37  	require.Len(t, LightningPrechecks, lightningCheck)
    38  	require.Error(t, ValidateCheckingItem("xxx"))
    39  
    40  	// ignore all checking items
    41  	ignoredCheckingItems := []string{AllChecking}
    42  	require.Nil(t, FilterCheckingItems(ignoredCheckingItems))
    43  	ignoredCheckingItems = append(ignoredCheckingItems, ShardTableSchemaChecking)
    44  	require.Nil(t, FilterCheckingItems(ignoredCheckingItems))
    45  
    46  	// ignore shard checking items
    47  	checkingItems := make(map[string]string)
    48  	for item, desc := range AllCheckingItems {
    49  		checkingItems[item] = desc
    50  	}
    51  	delete(checkingItems, AllChecking)
    52  
    53  	require.Equal(t, checkingItems, FilterCheckingItems(ignoredCheckingItems[:0]))
    54  
    55  	delete(checkingItems, ShardTableSchemaChecking)
    56  	require.Equal(t, checkingItems, FilterCheckingItems(ignoredCheckingItems[1:]))
    57  
    58  	ignoredCheckingItems = append(ignoredCheckingItems, ShardAutoIncrementIDChecking)
    59  	delete(checkingItems, ShardAutoIncrementIDChecking)
    60  	require.Equal(t, checkingItems, FilterCheckingItems(ignoredCheckingItems[1:]))
    61  }