vitess.io/vitess@v0.16.2/go/vt/topo/helpers/tee_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 "reflect" 21 "testing" 22 23 "github.com/stretchr/testify/require" 24 25 "context" 26 27 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 28 ) 29 30 func TestTee(t *testing.T) { 31 ctx := context.Background() 32 33 // create the setup, copy the data 34 fromTS, toTS := createSetup(ctx, t) 35 CopyKeyspaces(ctx, fromTS, toTS) 36 CopyShards(ctx, fromTS, toTS) 37 CopyTablets(ctx, fromTS, toTS) 38 39 // create a tee and check it implements the interface. 40 teeTS, err := NewTee(fromTS, toTS, true) 41 require.NoError(t, err) 42 43 // create a keyspace, make sure it is on both sides 44 if err := teeTS.CreateKeyspace(ctx, "keyspace2", &topodatapb.Keyspace{}); err != nil { 45 t.Fatalf("tee.CreateKeyspace(keyspace2) failed: %v", err) 46 } 47 teeKeyspaces, err := teeTS.GetKeyspaces(ctx) 48 if err != nil { 49 t.Fatalf("tee.GetKeyspaces() failed: %v", err) 50 } 51 expected := []string{"keyspace2", "test_keyspace"} 52 if !reflect.DeepEqual(expected, teeKeyspaces) { 53 t.Errorf("teeKeyspaces mismatch, got %+v, want %+v", teeKeyspaces, expected) 54 } 55 fromKeyspaces, err := fromTS.GetKeyspaces(ctx) 56 if err != nil { 57 t.Fatalf("fromTS.GetKeyspaces() failed: %v", err) 58 } 59 expected = []string{"keyspace2", "test_keyspace"} 60 if !reflect.DeepEqual(expected, fromKeyspaces) { 61 t.Errorf("fromKeyspaces mismatch, got %+v, want %+v", fromKeyspaces, expected) 62 } 63 toKeyspaces, err := toTS.GetKeyspaces(ctx) 64 if err != nil { 65 t.Fatalf("toTS.GetKeyspaces() failed: %v", err) 66 } 67 expected = []string{"keyspace2", "test_keyspace"} 68 if !reflect.DeepEqual(expected, toKeyspaces) { 69 t.Errorf("toKeyspaces mismatch, got %+v, want %+v", toKeyspaces, expected) 70 } 71 }