Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
492 changes: 157 additions & 335 deletions testproxypb/test_proxy.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions testproxypb/test_proxy_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/executequery_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ func mapType(key *btpb.Type, value *btpb.Type) *btpb.Type {
}
}

func protoType(name string) *btpb.Type {
return &btpb.Type{
Kind: &btpb.Type_ProtoType{
ProtoType: &btpb.Type_Proto{
MessageName: name,
},
},
}
}

func enumType(name string) *btpb.Type {
return &btpb.Type{
Kind: &btpb.Type_EnumType{
EnumType: &btpb.Type_Enum{
EnumName: name,
},
},
}
}

func strVal(v string) *btpb.Value {
return &btpb.Value{
Kind: &btpb.Value_StringValue{
Expand Down
42 changes: 41 additions & 1 deletion tests/executequery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/googleapis/cloud-bigtable-clients-test/testproxypb"
testpb "github.com/googleapis/cloud-bigtable-clients-test/tests/testdata"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/known/durationpb"
)

Expand Down Expand Up @@ -103,6 +108,25 @@ func assertErrorIn(t *testing.T, res *testproxypb.ExecuteQueryResult, messages [
}
}

// Returns a FileDescriptorSet containing the proto file descriptors for the provided proto messages.
// Messages must be provided in dependency order.
func buildFileDescriptorSet(msgs ...proto.Message) *descriptorpb.FileDescriptorSet {
files := protoregistry.GlobalFiles
seen := make(map[string]bool)
fds := &descriptorpb.FileDescriptorSet{}

for _, msg := range msgs {
filePath := msg.ProtoReflect().Descriptor().ParentFile().Path()
if !seen[filePath] {
if fd, err := files.FindFileByPath(filePath); err == nil && fd != nil {
fds.File = append(fds.File, protodesc.ToFileDescriptorProto(fd))
seen[filePath] = true
}
}
}
return fds
}

// Tests that a query will run successfully when receiving a response with no rows
func TestExecuteQuery_EmptyResponse(t *testing.T) {
// 1. Instantiate the mock server
Expand Down Expand Up @@ -209,7 +233,20 @@ func TestExecuteQuery_TypesTest(t *testing.T) {
arrayType(structType(
structField("timestamp", timestampType()),
structField("value", bytesType()))))),
column("protoCol", protoType(string(proto.MessageName(&testpb.Album{})))),
column("enumCol", enumType(string(testpb.Format(0).Descriptor().FullName()))),
}

album := &testpb.Album{
Title: "Lover",
Artist: &testpb.Singer{
Name: "Taylor Swift",
},
ReleaseYear: 2020,
Format: testpb.Format_CD,
}
serializedAlbum, _ := proto.Marshal(album)

expectedValues := []*btpb.Value{
strVal("strVal"),
bytesVal([]byte("bytesVal")),
Expand All @@ -225,6 +262,8 @@ func TestExecuteQuery_TypesTest(t *testing.T) {
mapVal(mapEntry(bytesVal([]byte("key")), arrayVal(
structVal(timestampVal(10000, 1000), bytesVal([]byte("val1"))),
structVal(timestampVal(20000, 1000), bytesVal([]byte("val2")))))),
bytesVal(serializedAlbum),
intVal(1),
}
server.PrepareQueryFn = mockPrepareQueryFn(nil,
&prepareQueryAction{
Expand All @@ -246,12 +285,13 @@ func TestExecuteQuery_TypesTest(t *testing.T) {
InstanceName: instanceName,
Query: "SELECT * FROM table",
},
FileDescriptorSet: buildFileDescriptorSet(&testpb.Singer{}, &testpb.Album{}),
}
// 3. Perform the operation via test proxy
res := doExecuteQueryOp(t, server, &req, nil)
// 4. Verify the read succeeds and gets the expected metadata & data
checkResultOkStatus(t, res)
assert.Equal(t, len(res.Metadata.Columns), 12)
assert.Equal(t, len(res.Metadata.Columns), 14)
assert.True(t, cmp.Equal(res.Metadata, testProxyMd(columns...), protocmp.Transform()))
assert.Equal(t, len(res.Rows), 1)
assertRowEqual(t, testProxyRow(expectedValues...), res.Rows[0], res.Metadata)
Expand Down
205 changes: 205 additions & 0 deletions tests/testdata/album.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testdata/album.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

import "tests/testdata/singer.proto";

package execute_query.test;
option go_package = "github.com/googleapis/cloud-bigtable-clients-test/tests/testdata;testpb";

enum Format {
CD = 0;
DIGITAL = 1;
}

message Album {
Singer artist = 1;
string title = 2;
int32 release_year = 3;
Format format = 4;
}
Loading