vitess.io/vitess@v0.16.2/go/vt/topo/helpers/compare_test.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package helpers
    18  
    19  import (
    20  	"testing"
    21  
    22  	"context"
    23  )
    24  
    25  func TestBasicCompare(t *testing.T) {
    26  	ctx := context.Background()
    27  	fromTS, toTS := createSetup(ctx, t)
    28  
    29  	// check compare keyspace compare
    30  	err := CompareKeyspaces(ctx, fromTS, toTS)
    31  	if err == nil {
    32  		t.Fatalf("Compare keyspaces is not failing when topos are not in sync")
    33  	}
    34  
    35  	CopyKeyspaces(ctx, fromTS, toTS)
    36  
    37  	err = CompareKeyspaces(ctx, fromTS, toTS)
    38  	if err != nil {
    39  		t.Fatalf("Compare keyspaces failed: %v", err)
    40  	}
    41  
    42  	// check shard copy
    43  	err = CompareShards(ctx, fromTS, toTS)
    44  	if err == nil {
    45  		t.Fatalf("Compare shards is not failing when topos are not in sync")
    46  	}
    47  
    48  	CopyShards(ctx, fromTS, toTS)
    49  
    50  	err = CompareShards(ctx, fromTS, toTS)
    51  	if err != nil {
    52  		t.Fatalf("Compare shards failed: %v", err)
    53  	}
    54  
    55  	// check ShardReplication compare
    56  	err = CompareShardReplications(ctx, fromTS, toTS)
    57  	if err == nil {
    58  		t.Fatalf("Compare shard replications is not failing when topos are not in sync")
    59  	}
    60  
    61  	CopyShardReplications(ctx, fromTS, toTS)
    62  
    63  	err = CompareShardReplications(ctx, fromTS, toTS)
    64  	if err != nil {
    65  		t.Fatalf("Compare shard replications failed: %v", err)
    66  	}
    67  
    68  	// check tablet compare
    69  	err = CompareTablets(ctx, fromTS, toTS)
    70  	if err == nil {
    71  		t.Fatalf("Compare tablets is not failing when topos are not in sync")
    72  	}
    73  
    74  	CopyTablets(ctx, fromTS, toTS)
    75  
    76  	err = CompareTablets(ctx, fromTS, toTS)
    77  	if err != nil {
    78  		t.Fatalf("Compare tablets failed: %v", err)
    79  	}
    80  
    81  	err = CompareRoutingRules(ctx, fromTS, toTS)
    82  	if err == nil {
    83  		t.Fatalf("Compare routing rules is not failing when topos are not in sync")
    84  	}
    85  
    86  	CopyRoutingRules(ctx, fromTS, toTS)
    87  
    88  	err = CompareRoutingRules(ctx, fromTS, toTS)
    89  	if err != nil {
    90  		t.Fatalf("Compare routing rules failed: %v", err)
    91  	}
    92  }