Skip to content

Commit

Permalink
fix(bigtable/bttest): Emulator too lenient for empty RowMutation (#4359)
Browse files Browse the repository at this point in the history
* fix(bigtable/bttest): Emulator too lenient for empty RowMutation

* gofmt

Co-authored-by: Christopher Wilcox <crwilcox@google.com>
  • Loading branch information
jimfulton and crwilcox committed Jul 27, 2021
1 parent b1b2afc commit 35ceae2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bigtable/bttest/inmem.go
Expand Up @@ -809,6 +809,12 @@ func newRegexp(pat []byte) (*binaryregexp.Regexp, error) {
}

func (s *server) MutateRow(ctx context.Context, req *btpb.MutateRowRequest) (*btpb.MutateRowResponse, error) {
if len(req.Mutations) == 0 {
return nil, status.Errorf(
codes.InvalidArgument,
"No mutations provided",
)
}
s.mu.Lock()
tbl, ok := s.tables[req.TableName]
s.mu.Unlock()
Expand All @@ -826,6 +832,16 @@ func (s *server) MutateRow(ctx context.Context, req *btpb.MutateRowRequest) (*bt
}

func (s *server) MutateRows(req *btpb.MutateRowsRequest, stream btpb.Bigtable_MutateRowsServer) error {
nMutations := 0
for _, entry := range req.Entries {
nMutations += len(entry.Mutations)
}
if nMutations == 0 {
return status.Errorf(
codes.InvalidArgument,
"No mutations provided",
)
}
s.mu.Lock()
tbl, ok := s.tables[req.TableName]
s.mu.Unlock()
Expand Down
44 changes: 44 additions & 0 deletions bigtable/bttest/inmem_test.go
Expand Up @@ -2034,6 +2034,50 @@ func TestValueFilterRowWithAlternationInRegex(t *testing.T) {
}
}

func TestMutateRowEmptyMutationErrors(t *testing.T) {
srv := &server{tables: make(map[string]*table)}
ctx := context.Background()
req := &btpb.MutateRowRequest{
TableName: "mytable",
RowKey: []byte("r"),
Mutations: []*btpb.Mutation{},
}

resp, err := srv.MutateRow(ctx, req)
if resp != nil ||
fmt.Sprint(err) !=
"rpc error: code = InvalidArgument"+
" desc = No mutations provided" {
t.Fatalf("Failed to error %s", err)
}
}

type bigtableTestingMutateRowsServer struct {
grpc.ServerStream
}

func (x *bigtableTestingMutateRowsServer) Send(m *btpb.MutateRowsResponse) error {
return nil
}

func TestMutateRowsEmptyMutationErrors(t *testing.T) {
srv := &server{tables: make(map[string]*table)}
req := &btpb.MutateRowsRequest{
TableName: "mytable",
Entries: []*btpb.MutateRowsRequest_Entry{
{Mutations: []*btpb.Mutation{}},
{Mutations: []*btpb.Mutation{}},
},
}

err := srv.MutateRows(req, &bigtableTestingMutateRowsServer{})
if fmt.Sprint(err) !=
"rpc error: code = InvalidArgument "+
"desc = No mutations provided" {
t.Fatalf("Failed to error %s", err)
}
}

func TestFilterRowCellsPerRowLimitFilterTruthiness(t *testing.T) {
row := &row{
key: "row",
Expand Down

0 comments on commit 35ceae2

Please sign in to comment.