Skip to content

Commit

Permalink
fix(bigquery): readability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarowolfx committed Sep 20, 2022
1 parent c412574 commit a905f3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bigquery/routine.go
Expand Up @@ -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
Expand Down
35 changes: 17 additions & 18 deletions bigquery/routine_integration_test.go
Expand Up @@ -17,7 +17,6 @@ package bigquery
import (
"context"
"fmt"
"log"
"strings"
"testing"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit a905f3d

Please sign in to comment.