vitess.io/vitess@v0.16.2/go/vt/srvtopo/srvtopotest/passthrough.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 srvtopotest 18 19 import ( 20 "context" 21 22 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 23 vschemapb "vitess.io/vitess/go/vt/proto/vschema" 24 "vitess.io/vitess/go/vt/topo" 25 ) 26 27 // PassthroughSrvTopoServer is a bare implementation of srvtopo.Server for use in tests 28 type PassthroughSrvTopoServer struct { 29 TopoServer *topo.Server 30 TopoServerError error 31 32 SrvKeyspaceNames []string 33 SrvKeyspaceNamesError error 34 35 SrvKeyspace *topodatapb.SrvKeyspace 36 SrvKeyspaceError error 37 38 WatchedSrvVSchema *vschemapb.SrvVSchema 39 WatchedSrvVSchemaError error 40 } 41 42 // NewPassthroughSrvTopoServer returns a new, unconfigured test PassthroughSrvTopoServer 43 func NewPassthroughSrvTopoServer() *PassthroughSrvTopoServer { 44 return &PassthroughSrvTopoServer{} 45 } 46 47 // GetTopoServer implements srvtopo.Server 48 func (srv *PassthroughSrvTopoServer) GetTopoServer() (*topo.Server, error) { 49 return srv.TopoServer, srv.TopoServerError 50 } 51 52 // GetSrvKeyspaceNames implements srvtopo.Server 53 func (srv *PassthroughSrvTopoServer) GetSrvKeyspaceNames(ctx context.Context, cell string, staleOK bool) ([]string, error) { 54 return srv.SrvKeyspaceNames, srv.SrvKeyspaceNamesError 55 } 56 57 // GetSrvKeyspace implements srvtopo.Server 58 func (srv *PassthroughSrvTopoServer) GetSrvKeyspace(ctx context.Context, cell, keyspace string) (*topodatapb.SrvKeyspace, error) { 59 return srv.SrvKeyspace, srv.SrvKeyspaceError 60 } 61 62 func (srv *PassthroughSrvTopoServer) WatchSrvKeyspace(ctx context.Context, cell, keyspace string, callback func(*topodatapb.SrvKeyspace, error) bool) { 63 callback(srv.SrvKeyspace, srv.SrvKeyspaceError) 64 } 65 66 // WatchSrvVSchema implements srvtopo.Server 67 func (srv *PassthroughSrvTopoServer) WatchSrvVSchema(ctx context.Context, cell string, callback func(*vschemapb.SrvVSchema, error) bool) { 68 callback(srv.WatchedSrvVSchema, srv.WatchedSrvVSchemaError) 69 }