From a905f3db360d74a5ed125d0d132af8a4469d93f8 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Tue, 20 Sep 2022 17:03:23 -0400 Subject: [PATCH] fix(bigquery): readability improvements --- bigquery/routine.go | 2 +- bigquery/routine_integration_test.go | 35 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bigquery/routine.go b/bigquery/routine.go index 1a064b3be081..2274f33fe360 100644 --- a/bigquery/routine.go +++ b/bigquery/routine.go @@ -188,7 +188,7 @@ type RoutineMetadata struct { // The list of arguments for the the routine. Arguments []*RoutineArgument - // Information to for a remote user-defined function. + // Information for a remote user-defined function. RemoteFunctionOptions *RemoteFunctionOptions ReturnType *StandardSQLDataType diff --git a/bigquery/routine_integration_test.go b/bigquery/routine_integration_test.go index e4a14f2a6baa..744bdc73ed3c 100644 --- a/bigquery/routine_integration_test.go +++ b/bigquery/routine_integration_test.go @@ -17,7 +17,6 @@ package bigquery import ( "context" "fmt" - "log" "strings" "testing" @@ -98,20 +97,20 @@ func TestIntegration_RoutineRemoteUDF(t *testing.T) { } ctx := context.Background() - parentLocation := fmt.Sprintf("projects/%s/locations/%s", dataset.ProjectID, "us-central1") + functionLocation := fmt.Sprintf("projects/%s/locations/%s", dataset.ProjectID, "us-central1") routineID := routineIDs.New() routine := dataset.Routine(routineID) functionName := fmt.Sprintf("udf-func-%s", strings.ReplaceAll(routineID, "_", "-")) - cleanupFunction, uri, err := createCloudFunction(ctx, t, parentLocation, functionName) + cleanupFunction, uri, err := createCloudFunction(ctx, t, functionLocation, functionName) if err != nil { t.Fatal(err) } defer cleanupFunction() - parentLocation = fmt.Sprintf("projects/%s/locations/%s", dataset.ProjectID, "us") + connectionLocation := fmt.Sprintf("projects/%s/locations/%s", dataset.ProjectID, "us") connectionName := fmt.Sprintf("udf_conn%s", routineID) - cleanupConnection, connectionID, err := createConnection(ctx, t, parentLocation, connectionName) + cleanupConnection, connectionID, err := createConnection(ctx, t, connectionLocation, connectionName) if err != nil { t.Fatal(err) } @@ -145,9 +144,8 @@ func TestIntegration_RoutineRemoteUDF(t *testing.T) { } } -func createCloudFunction(ctx context.Context, t *testing.T, parent, functionName string) (func(), string, error) { +func createCloudFunction(ctx context.Context, t *testing.T, parent, functionName string) (cleanup func(), uri string, err error) { fullname := fmt.Sprintf("%s/services/%s", parent, functionName) - cleanup := func() {} createOps, err := functionsClient.CreateService(ctx, &run.CreateServiceRequest{ Parent: parent, ServiceId: functionName, @@ -163,32 +161,32 @@ func createCloudFunction(ctx context.Context, t *testing.T, parent, functionName }, }) if err != nil { - return cleanup, "", err + return } _, err = createOps.Wait(ctx) if err != nil { - return cleanup, "", err + return } service, err := functionsClient.GetService(ctx, &run.GetServiceRequest{ Name: fullname, }) if err != nil { - return cleanup, "", err + return } cleanup = func() { _, err := functionsClient.DeleteService(ctx, &run.DeleteServiceRequest{ Name: fullname, }) if err != nil { - log.Printf("could not delete %s", fullname) + t.Logf("could not delete cloud run service: %s", fullname) } } - return cleanup, service.GetUri(), nil + uri = service.GetUri() + return } -func createConnection(ctx context.Context, t *testing.T, parent, name string) (func(), string, error) { +func createConnection(ctx context.Context, t *testing.T, parent, name string) (cleanup func(), connectionID string, err error) { fullname := fmt.Sprintf("%s/connections/%s", parent, name) - cleanup := func() {} conn, err := connectionsClient.CreateConnection(ctx, &connection.CreateConnectionRequest{ Parent: parent, ConnectionId: name, @@ -200,23 +198,24 @@ func createConnection(ctx context.Context, t *testing.T, parent, name string) (f }, }) if err != nil { - return cleanup, "", err + return } conn, err = connectionsClient.GetConnection(ctx, &connection.GetConnectionRequest{ Name: fullname, }) if err != nil { - return cleanup, "", err + return } cleanup = func() { err := connectionsClient.DeleteConnection(ctx, &connection.DeleteConnectionRequest{ Name: fullname, }) if err != nil { - log.Printf("could not delete %s", fullname) + t.Logf("could not delete connection: %s", fullname) } } - return cleanup, conn.Name, nil + connectionID = conn.Name + return } func TestIntegration_RoutineComplexTypes(t *testing.T) {