vitess.io/vitess@v0.16.2/go/vt/vtctl/grpcvtctldserver/testutil/srv_keyspace.go (about) 1 /* 2 Copyright 2021 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 testutil 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/stretchr/testify/require" 24 25 "vitess.io/vitess/go/vt/topo" 26 27 topodatapb "vitess.io/vitess/go/vt/proto/topodata" 28 ) 29 30 // SrvKeyspace groups a topodatapb.SrvKeyspace together with a keyspace and 31 // cell. 32 type SrvKeyspace struct { 33 Keyspace string 34 Cell string 35 SrvKeyspace *topodatapb.SrvKeyspace 36 } 37 38 // AddSrvKeyspaces adds one or more SrvKeyspace objects to the topology. It 39 // fails the calling test if any of the objects fail to update. 40 func AddSrvKeyspaces(t *testing.T, ts *topo.Server, srvKeyspaces ...*SrvKeyspace) { 41 t.Helper() 42 43 ctx := context.Background() 44 45 for _, sk := range srvKeyspaces { 46 err := ts.UpdateSrvKeyspace(ctx, sk.Cell, sk.Keyspace, sk.SrvKeyspace) 47 require.NoError(t, err, "UpdateSrvKeyspace(cell = %v, keyspace = %v, srv_keyspace = %v", sk.Cell, sk.Keyspace, sk.SrvKeyspace) 48 } 49 }