github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/regionspan/region_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 regionspan
    15  
    16  import (
    17  	"github.com/pingcap/check"
    18  	"github.com/pingcap/kvproto/pkg/metapb"
    19  	"github.com/pingcap/ticdc/pkg/util/testleak"
    20  )
    21  
    22  type regionSuite struct{}
    23  
    24  var _ = check.Suite(&regionSuite{})
    25  
    26  func (s *regionSuite) TestCheckRegionsLeftCover(c *check.C) {
    27  	defer testleak.AfterTest(c)()
    28  	cases := []struct {
    29  		regions []*metapb.Region
    30  		span    ComparableSpan
    31  		cover   bool
    32  	}{
    33  		{[]*metapb.Region{}, ComparableSpan{[]byte{1}, []byte{2}}, false},
    34  		{[]*metapb.Region{{StartKey: nil, EndKey: nil}}, ComparableSpan{[]byte{1}, []byte{2}}, true},
    35  		{[]*metapb.Region{{StartKey: []byte{1}, EndKey: []byte{2}}}, ComparableSpan{[]byte{1}, []byte{2}}, true},
    36  		{[]*metapb.Region{{StartKey: []byte{0}, EndKey: []byte{4}}}, ComparableSpan{[]byte{1}, []byte{2}}, true},
    37  		{[]*metapb.Region{
    38  			{StartKey: []byte{1}, EndKey: []byte{2}},
    39  			{StartKey: []byte{2}, EndKey: []byte{3}},
    40  		}, ComparableSpan{[]byte{1}, []byte{3}}, true},
    41  		{[]*metapb.Region{
    42  			{StartKey: []byte{1}, EndKey: []byte{2}},
    43  			{StartKey: []byte{3}, EndKey: []byte{4}},
    44  		}, ComparableSpan{[]byte{1}, []byte{4}}, false},
    45  		{[]*metapb.Region{
    46  			{StartKey: []byte{1}, EndKey: []byte{2}},
    47  			{StartKey: []byte{2}, EndKey: []byte{3}},
    48  		}, ComparableSpan{[]byte{1}, []byte{4}}, true},
    49  		{[]*metapb.Region{
    50  			{StartKey: []byte{2}, EndKey: []byte{3}},
    51  		}, ComparableSpan{[]byte{1}, []byte{3}}, false},
    52  	}
    53  
    54  	for _, tc := range cases {
    55  		c.Assert(CheckRegionsLeftCover(tc.regions, tc.span), check.Equals, tc.cover)
    56  	}
    57  }