Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions go/cmd/vttestserver/cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ import (
"context"
"fmt"
"io"
"maps"
"math/rand/v2"
"os/exec"
"path"
<<<<<<< HEAD
||||||| parent of bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740))
"strconv"
=======
"slices"
"strconv"
>>>>>>> bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740))
"strings"
Comment on lines 20 to 28
"testing"
"time"
Expand Down Expand Up @@ -421,12 +429,31 @@ func assertColumnVindex(t *testing.T, cluster vttest.LocalCluster, expected colu

err := vtctlclient.RunCommandAndWait(ctx, server, args, func(e *logutilpb.Event) {
var keyspace vschemapb.Keyspace
<<<<<<< HEAD
if err := protojson.Unmarshal([]byte(e.Value), &keyspace); err != nil {
t.Error(err)
}
||||||| parent of bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740))
if err := protojson.Unmarshal([]byte(e.Value), &keyspace); err != nil {
assert.NoError(t, err)
}
=======
require.NoError(t, protojson.Unmarshal([]byte(e.Value), &keyspace))

// Look the table and vindex up before dereferencing them, so that a
// vschema missing either fails with a message naming what was missing
// instead of panicking on a nil map entry and taking down the whole
// test binary.
table, ok := keyspace.Tables[expected.table]
require.Truef(t, ok, "keyspace %s has no table %s in its vschema, found tables %v", expected.keyspace, expected.table, slices.Sorted(maps.Keys(keyspace.Tables)))
Comment on lines +432 to +433

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a regression test that reaches the missing-entry guards

Every caller still requests tables and vindexes present in the fixture, so these new branches are never exercised and the suite passes identically if the guards are reverted to the panicking implementation. Add a focused test that supplies a missing table and vindex and verifies that validation reports a test failure rather than panicking; otherwise CI does not prove the behavior this commit claims to fix.

AGENTS.md reference: AGENTS.md:L72-L73

Useful? React with 👍 / 👎.

require.NotEmptyf(t, table.ColumnVindexes, "table %s.%s has no column vindexes", expected.keyspace, expected.table)
columnVindex := table.ColumnVindexes[0]
require.NotEmptyf(t, columnVindex.Columns, "column vindex %s on %s.%s has no columns", columnVindex.Name, expected.keyspace, expected.table)

actualVindex, ok := keyspace.Vindexes[expected.vindex]
require.Truef(t, ok, "keyspace %s has no vindex %s in its vschema, found vindexes %v", expected.keyspace, expected.vindex, slices.Sorted(maps.Keys(keyspace.Vindexes)))
>>>>>>> bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740))

columnVindex := keyspace.Tables[expected.table].ColumnVindexes[0]
actualVindex := keyspace.Vindexes[expected.vindex]
assertEqual(t, actualVindex.Type, expected.vindexType, "Actual vindex type different from expected")
assertEqual(t, columnVindex.Name, expected.vindex, "Actual vindex name different from expected")
assertEqual(t, columnVindex.Columns[0], expected.column, "Actual vindex column different from expected")
Expand Down
Loading