Skip to content

Commit 733fc1c

Browse files
committed
test: make it easier to run without a main keyspace
Signed-off-by: Andres Taylor <[email protected]>
1 parent aabf1c9 commit 733fc1c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

go/test/vschemawrapper/vschema_wrapper.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package vschemawrapper
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"strings"
2324

@@ -275,17 +276,6 @@ func (vw *VSchemaWrapper) FindTableOrVindex(tab sqlparser.TableName) (*vindexes.
275276
return vw.Vcursor.FindTableOrVindex(tab)
276277
}
277278

278-
func (vw *VSchemaWrapper) getfirstKeyspace() (ks *vindexes.Keyspace) {
279-
var f string
280-
for name, schema := range vw.V.Keyspaces {
281-
if f == "" || f > name {
282-
f = name
283-
ks = schema.Keyspace
284-
}
285-
}
286-
return
287-
}
288-
289279
func (vw *VSchemaWrapper) getActualKeyspace() string {
290280
if vw.Keyspace == nil {
291281
return ""
@@ -301,15 +291,24 @@ func (vw *VSchemaWrapper) getActualKeyspace() string {
301291
}
302292

303293
func (vw *VSchemaWrapper) SelectedKeyspace() (*vindexes.Keyspace, error) {
304-
return vw.V.Keyspaces["main"].Keyspace, nil
294+
return vw.AnyKeyspace()
305295
}
306296

307297
func (vw *VSchemaWrapper) AnyKeyspace() (*vindexes.Keyspace, error) {
308-
return vw.SelectedKeyspace()
298+
ks, found := vw.V.Keyspaces["main"]
299+
if found {
300+
return ks.Keyspace, nil
301+
}
302+
303+
for _, ks := range vw.V.Keyspaces {
304+
return ks.Keyspace, nil
305+
}
306+
307+
return nil, errors.New("no keyspace found in vschema")
309308
}
310309

311310
func (vw *VSchemaWrapper) FirstSortedKeyspace() (*vindexes.Keyspace, error) {
312-
return vw.V.Keyspaces["main"].Keyspace, nil
311+
return vw.AnyKeyspace()
313312
}
314313

315314
func (vw *VSchemaWrapper) TargetString() string {
@@ -344,12 +343,12 @@ func (vw *VSchemaWrapper) IsViewsEnabled() bool {
344343

345344
// FindMirrorRule finds the mirror rule for the requested keyspace, table
346345
// name, and the tablet type in the VSchema.
347-
func (vs *VSchemaWrapper) FindMirrorRule(tab sqlparser.TableName) (*vindexes.MirrorRule, error) {
346+
func (vw *VSchemaWrapper) FindMirrorRule(tab sqlparser.TableName) (*vindexes.MirrorRule, error) {
348347
destKeyspace, destTabletType, _, err := topoproto.ParseDestination(tab.Qualifier.String(), topodatapb.TabletType_PRIMARY)
349348
if err != nil {
350349
return nil, err
351350
}
352-
mirrorRule, err := vs.V.FindMirrorRule(destKeyspace, tab.Name.String(), destTabletType)
351+
mirrorRule, err := vw.V.FindMirrorRule(destKeyspace, tab.Name.String(), destTabletType)
353352
if err != nil {
354353
return nil, err
355354
}

0 commit comments

Comments
 (0)