vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vdiff/action_test.go (about) 1 /* 2 Copyright 2022 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 vdiff 18 19 import ( 20 "context" 21 "reflect" 22 "testing" 23 "time" 24 25 tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" 26 vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" 27 "vitess.io/vitess/go/vt/vterrors" 28 ) 29 30 func TestPerformVDiffAction(t *testing.T) { 31 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) 32 defer cancel() 33 tests := []struct { 34 name string 35 vde *Engine 36 req *tabletmanagerdatapb.VDiffRequest 37 want *tabletmanagerdatapb.VDiffResponse 38 wantErr error 39 }{ 40 { 41 name: "engine not open", 42 vde: &Engine{isOpen: false}, 43 wantErr: vterrors.New(vtrpcpb.Code_UNAVAILABLE, "vdiff engine is closed"), 44 }, 45 } 46 for _, tt := range tests { 47 t.Run(tt.name, func(t *testing.T) { 48 got, err := tt.vde.PerformVDiffAction(ctx, tt.req) 49 if tt.wantErr != nil && !vterrors.Equals(err, tt.wantErr) { 50 t.Errorf("Engine.PerformVDiffAction() error = %v, wantErr %v", err, tt.wantErr) 51 return 52 } 53 if !reflect.DeepEqual(got, tt.want) { 54 t.Errorf("Engine.PerformVDiffAction() = %v, want %v", got, tt.want) 55 } 56 }) 57 } 58 }