Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing(bigquery/storage/managedwriter): dynamic schema test fixes #10318

Merged
merged 6 commits into from
Jul 22, 2024
Merged
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
20 changes: 13 additions & 7 deletions bigquery/storage/managedwriter/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ func setupTestDataset(ctx context.Context, t *testing.T, bqc *bigquery.Client, l
}, nil
}

// setupDynamicDescriptors aids testing when not using a supplied proto
func setupDynamicDescriptors(t *testing.T, schema bigquery.Schema) (protoreflect.MessageDescriptor, *descriptorpb.DescriptorProto) {
convertedSchema, err := adapt.BQSchemaToStorageTableSchema(schema)
// setupDynamicDescriptors aids testing when not using a supplied proto.
func setupDynamicDescriptors(ctx context.Context, t *testing.T, c *Client, streamName string) (protoreflect.MessageDescriptor, *descriptorpb.DescriptorProto) {

resp, err := c.GetWriteStream(ctx, &storagepb.GetWriteStreamRequest{
Name: streamName,
View: storagepb.WriteStreamView_FULL,
})
if err != nil {
t.Fatalf("adapt.BQSchemaToStorageTableSchema: %v", err)
t.Fatalf("couldn't get write stream (%q): %v", streamName, err)
}

descriptor, err := adapt.StorageSchemaToProto2Descriptor(convertedSchema, "root")
descriptor, err := adapt.StorageSchemaToProto2Descriptor(resp.GetTableSchema(), "root")
if err != nil {
t.Fatalf("adapt.StorageSchemaToDescriptor: %v", err)
}
Expand Down Expand Up @@ -404,7 +408,8 @@ func testDefaultStreamDynamicJSON(ctx context.Context, t *testing.T, mwClient *C
t.Fatalf("failed to create test table %s: %v", testTable.FullyQualifiedName(), err)
}

md, descriptorProto := setupDynamicDescriptors(t, testdata.GithubArchiveSchema)
defStreamName := fmt.Sprintf("%s/streams/_default", TableParentFromParts(testTable.ProjectID, testTable.DatasetID, testTable.TableID))
md, descriptorProto := setupDynamicDescriptors(ctx, t, mwClient, defStreamName)

ms, err := mwClient.NewManagedStream(ctx,
WithDestinationTable(TableParentFromParts(testTable.ProjectID, testTable.DatasetID, testTable.TableID)),
Expand Down Expand Up @@ -465,7 +470,8 @@ func testDefaultStreamJSONData(ctx context.Context, t *testing.T, mwClient *Clie
t.Fatalf("failed to create test table %s: %v", testTable.FullyQualifiedName(), err)
}

md, descriptorProto := setupDynamicDescriptors(t, testdata.ComplexTypeSchema)
defStreamName := fmt.Sprintf("%s/streams/_default", TableParentFromParts(testTable.ProjectID, testTable.DatasetID, testTable.TableID))
md, descriptorProto := setupDynamicDescriptors(ctx, t, mwClient, defStreamName)

ms, err := mwClient.NewManagedStream(ctx,
WithDestinationTable(TableParentFromParts(testTable.ProjectID, testTable.DatasetID, testTable.TableID)),
Expand Down
6 changes: 5 additions & 1 deletion bigquery/storage/managedwriter/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,14 @@ func TestValidation_Values(t *testing.T) {
t.Errorf("%s append failed: %v", tc.description, err)
continue
}
if _, err = result.GetResult(ctx); err != nil {
resp, err := result.FullResponse(ctx)
if err != nil {
t.Errorf("%s append response error: %v", tc.description, err)
continue
}
if status := resp.GetError(); status != nil {
t.Errorf("%s append response embeds an error: %v", tc.description, status)
}
// Validate table.
validateTableConstraints(ctx, t, bqClient, testTable, tc.description, tc.constraints...)
}
Expand Down
Loading