vendor: update all dependencies
This commit is contained in:
+98
-86
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"cloud.google.com/go/internal/version"
|
||||
"cloud.google.com/go/longrunning"
|
||||
lroauto "cloud.google.com/go/longrunning/autogen"
|
||||
gax "github.com/googleapis/gax-go"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
@@ -55,10 +56,7 @@ type DatabaseAdminCallOptions struct {
|
||||
func defaultDatabaseAdminClientOptions() []option.ClientOption {
|
||||
return []option.ClientOption{
|
||||
option.WithEndpoint("spanner.googleapis.com:443"),
|
||||
option.WithScopes(
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/spanner.admin",
|
||||
),
|
||||
option.WithScopes(DefaultAuthScopes()...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,17 +74,6 @@ func defaultDatabaseAdminCallOptions() *DatabaseAdminCallOptions {
|
||||
})
|
||||
}),
|
||||
},
|
||||
{"default", "non_idempotent"}: {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 1000 * time.Millisecond,
|
||||
Max: 32000 * time.Millisecond,
|
||||
Multiplier: 1.3,
|
||||
})
|
||||
}),
|
||||
},
|
||||
}
|
||||
return &DatabaseAdminCallOptions{
|
||||
ListDatabases: retry[[2]string{"default", "idempotent"}],
|
||||
@@ -109,11 +96,16 @@ type DatabaseAdminClient struct {
|
||||
// The gRPC API client.
|
||||
databaseAdminClient databasepb.DatabaseAdminClient
|
||||
|
||||
// LROClient is used internally to handle longrunning operations.
|
||||
// It is exposed so that its CallOptions can be modified if required.
|
||||
// Users should not Close this client.
|
||||
LROClient *lroauto.OperationsClient
|
||||
|
||||
// The call options for this service.
|
||||
CallOptions *DatabaseAdminCallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
xGoogHeader string
|
||||
xGoogHeader []string
|
||||
}
|
||||
|
||||
// NewDatabaseAdminClient creates a new database admin client.
|
||||
@@ -135,6 +127,17 @@ func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*
|
||||
databaseAdminClient: databasepb.NewDatabaseAdminClient(conn),
|
||||
}
|
||||
c.SetGoogleClientInfo()
|
||||
|
||||
c.LROClient, err = lroauto.NewOperationsClient(ctx, option.WithGRPCConn(conn))
|
||||
if err != nil {
|
||||
// This error "should not happen", since we are just reusing old connection
|
||||
// and never actually need to dial.
|
||||
// If this does happen, we could leak conn. However, we cannot close conn:
|
||||
// If the user invoked the function with option.WithGRPCConn,
|
||||
// we would close a connection that's still in use.
|
||||
// TODO(pongad): investigate error conditions.
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -154,8 +157,8 @@ func (c *DatabaseAdminClient) Close() error {
|
||||
// use by Google-written clients.
|
||||
func (c *DatabaseAdminClient) SetGoogleClientInfo(keyval ...string) {
|
||||
kv := append([]string{"gl-go", version.Go()}, keyval...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
|
||||
c.xGoogHeader = gax.XGoogHeader(kv...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
|
||||
c.xGoogHeader = []string{gax.XGoogHeader(kv...)}
|
||||
}
|
||||
|
||||
// DatabaseAdminInstancePath returns the path for the instance resource.
|
||||
@@ -184,8 +187,9 @@ func DatabaseAdminDatabasePath(project, instance, database string) string {
|
||||
}
|
||||
|
||||
// ListDatabases lists Cloud Spanner databases.
|
||||
func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest) *DatabaseIterator {
|
||||
func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest, opts ...gax.CallOption) *DatabaseIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListDatabases[0:len(c.CallOptions.ListDatabases):len(c.CallOptions.ListDatabases)], opts...)
|
||||
it := &DatabaseIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*databasepb.Database, string, error) {
|
||||
var resp *databasepb.ListDatabasesResponse
|
||||
@@ -195,11 +199,11 @@ func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.ListDatabases(ctx, req)
|
||||
resp, err = c.databaseAdminClient.ListDatabases(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListDatabases...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -225,31 +229,33 @@ func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb
|
||||
// [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. The
|
||||
// [response][google.longrunning.Operation.response] field type is
|
||||
// [Database][google.spanner.admin.database.v1.Database], if successful.
|
||||
func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest) (*DatabaseOperation, error) {
|
||||
func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.CreateDatabase[0:len(c.CallOptions.CreateDatabase):len(c.CallOptions.CreateDatabase)], opts...)
|
||||
var resp *longrunningpb.Operation
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.CreateDatabase(ctx, req)
|
||||
resp, err = c.databaseAdminClient.CreateDatabase(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.CreateDatabase...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &DatabaseOperation{
|
||||
lro: longrunning.InternalNewOperation(c.Connection(), resp),
|
||||
return &CreateDatabaseOperation{
|
||||
lro: longrunning.InternalNewOperation(c.LROClient, resp),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetDatabase gets the state of a Cloud Spanner database.
|
||||
func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest) (*databasepb.Database, error) {
|
||||
func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest, opts ...gax.CallOption) (*databasepb.Database, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.GetDatabase[0:len(c.CallOptions.GetDatabase):len(c.CallOptions.GetDatabase)], opts...)
|
||||
var resp *databasepb.Database
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.GetDatabase(ctx, req)
|
||||
resp, err = c.databaseAdminClient.GetDatabase(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.GetDatabase...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -263,44 +269,47 @@ func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.G
|
||||
// track execution of the schema change(s). The
|
||||
// [metadata][google.longrunning.Operation.metadata] field type is
|
||||
// [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. The operation has no response.
|
||||
func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest) (*EmptyOperation, error) {
|
||||
func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest, opts ...gax.CallOption) (*UpdateDatabaseDdlOperation, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.UpdateDatabaseDdl[0:len(c.CallOptions.UpdateDatabaseDdl):len(c.CallOptions.UpdateDatabaseDdl)], opts...)
|
||||
var resp *longrunningpb.Operation
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.UpdateDatabaseDdl(ctx, req)
|
||||
resp, err = c.databaseAdminClient.UpdateDatabaseDdl(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.UpdateDatabaseDdl...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &EmptyOperation{
|
||||
lro: longrunning.InternalNewOperation(c.Connection(), resp),
|
||||
return &UpdateDatabaseDdlOperation{
|
||||
lro: longrunning.InternalNewOperation(c.LROClient, resp),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DropDatabase drops (aka deletes) a Cloud Spanner database.
|
||||
func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest) error {
|
||||
func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
opts = append(c.CallOptions.DropDatabase[0:len(c.CallOptions.DropDatabase):len(c.CallOptions.DropDatabase)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
_, err = c.databaseAdminClient.DropDatabase(ctx, req)
|
||||
_, err = c.databaseAdminClient.DropDatabase(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.DropDatabase...)
|
||||
}, opts...)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetDatabaseDdl returns the schema of a Cloud Spanner database as a list of formatted
|
||||
// DDL statements. This method does not show pending schema updates, those may
|
||||
// be queried using the [Operations][google.longrunning.Operations] API.
|
||||
func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest) (*databasepb.GetDatabaseDdlResponse, error) {
|
||||
func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest, opts ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.GetDatabaseDdl[0:len(c.CallOptions.GetDatabaseDdl):len(c.CallOptions.GetDatabaseDdl)], opts...)
|
||||
var resp *databasepb.GetDatabaseDdlResponse
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.GetDatabaseDdl(ctx, req)
|
||||
resp, err = c.databaseAdminClient.GetDatabaseDdl(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.GetDatabaseDdl...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -312,14 +321,15 @@ func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasep
|
||||
//
|
||||
// Authorization requires `spanner.databases.setIamPolicy` permission on
|
||||
// [resource][google.iam.v1.SetIamPolicyRequest.resource].
|
||||
func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.SetIamPolicy[0:len(c.CallOptions.SetIamPolicy):len(c.CallOptions.SetIamPolicy)], opts...)
|
||||
var resp *iampb.Policy
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.SetIamPolicy(ctx, req)
|
||||
resp, err = c.databaseAdminClient.SetIamPolicy(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.SetIamPolicy...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,14 +341,15 @@ func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIa
|
||||
//
|
||||
// Authorization requires `spanner.databases.getIamPolicy` permission on
|
||||
// [resource][google.iam.v1.GetIamPolicyRequest.resource].
|
||||
func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.GetIamPolicy[0:len(c.CallOptions.GetIamPolicy):len(c.CallOptions.GetIamPolicy)], opts...)
|
||||
var resp *iampb.Policy
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.GetIamPolicy(ctx, req)
|
||||
resp, err = c.databaseAdminClient.GetIamPolicy(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.GetIamPolicy...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -351,14 +362,15 @@ func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIa
|
||||
// a NOT_FOUND error if the user has `spanner.databases.list` permission on
|
||||
// the containing Cloud Spanner instance. Otherwise returns an empty set of
|
||||
// permissions.
|
||||
func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error) {
|
||||
func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.TestIamPermissions[0:len(c.CallOptions.TestIamPermissions):len(c.CallOptions.TestIamPermissions)], opts...)
|
||||
var resp *iampb.TestIamPermissionsResponse
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.databaseAdminClient.TestIamPermissions(ctx, req)
|
||||
resp, err = c.databaseAdminClient.TestIamPermissions(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.TestIamPermissions...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -407,25 +419,25 @@ func (it *DatabaseIterator) takeBuf() interface{} {
|
||||
return b
|
||||
}
|
||||
|
||||
// DatabaseOperation manages a long-running operation yielding databasepb.Database.
|
||||
type DatabaseOperation struct {
|
||||
// CreateDatabaseOperation manages a long-running operation from CreateDatabase.
|
||||
type CreateDatabaseOperation struct {
|
||||
lro *longrunning.Operation
|
||||
}
|
||||
|
||||
// DatabaseOperation returns a new DatabaseOperation from a given name.
|
||||
// The name must be that of a previously created DatabaseOperation, possibly from a different process.
|
||||
func (c *DatabaseAdminClient) DatabaseOperation(name string) *DatabaseOperation {
|
||||
return &DatabaseOperation{
|
||||
lro: longrunning.InternalNewOperation(c.Connection(), &longrunningpb.Operation{Name: name}),
|
||||
// CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name.
|
||||
// The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
|
||||
func (c *DatabaseAdminClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation {
|
||||
return &CreateDatabaseOperation{
|
||||
lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
|
||||
}
|
||||
}
|
||||
|
||||
// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
|
||||
//
|
||||
// See documentation of Poll for error-handling information.
|
||||
func (op *DatabaseOperation) Wait(ctx context.Context) (*databasepb.Database, error) {
|
||||
func (op *CreateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
|
||||
var resp databasepb.Database
|
||||
if err := op.lro.Wait(ctx, &resp); err != nil {
|
||||
if err := op.lro.Wait(ctx, &resp, opts...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
@@ -440,9 +452,9 @@ func (op *DatabaseOperation) Wait(ctx context.Context) (*databasepb.Database, er
|
||||
// If Poll succeeds and the operation has completed successfully,
|
||||
// op.Done will return true, and the response of the operation is returned.
|
||||
// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
|
||||
func (op *DatabaseOperation) Poll(ctx context.Context) (*databasepb.Database, error) {
|
||||
func (op *CreateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
|
||||
var resp databasepb.Database
|
||||
if err := op.lro.Poll(ctx, &resp); err != nil {
|
||||
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !op.Done() {
|
||||
@@ -455,7 +467,7 @@ func (op *DatabaseOperation) Poll(ctx context.Context) (*databasepb.Database, er
|
||||
// Metadata itself does not contact the server, but Poll does.
|
||||
// To get the latest metadata, call this method after a successful call to Poll.
|
||||
// If the metadata is not available, the returned metadata and error are both nil.
|
||||
func (op *DatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error) {
|
||||
func (op *CreateDatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error) {
|
||||
var meta databasepb.CreateDatabaseMetadata
|
||||
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
|
||||
return nil, nil
|
||||
@@ -466,34 +478,34 @@ func (op *DatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, err
|
||||
}
|
||||
|
||||
// Done reports whether the long-running operation has completed.
|
||||
func (op *DatabaseOperation) Done() bool {
|
||||
func (op *CreateDatabaseOperation) Done() bool {
|
||||
return op.lro.Done()
|
||||
}
|
||||
|
||||
// Name returns the name of the long-running operation.
|
||||
// The name is assigned by the server and is unique within the service from which the operation is created.
|
||||
func (op *DatabaseOperation) Name() string {
|
||||
func (op *CreateDatabaseOperation) Name() string {
|
||||
return op.lro.Name()
|
||||
}
|
||||
|
||||
// EmptyOperation manages a long-running operation with no result.
|
||||
type EmptyOperation struct {
|
||||
// UpdateDatabaseDdlOperation manages a long-running operation from UpdateDatabaseDdl.
|
||||
type UpdateDatabaseDdlOperation struct {
|
||||
lro *longrunning.Operation
|
||||
}
|
||||
|
||||
// EmptyOperation returns a new EmptyOperation from a given name.
|
||||
// The name must be that of a previously created EmptyOperation, possibly from a different process.
|
||||
func (c *DatabaseAdminClient) EmptyOperation(name string) *EmptyOperation {
|
||||
return &EmptyOperation{
|
||||
lro: longrunning.InternalNewOperation(c.Connection(), &longrunningpb.Operation{Name: name}),
|
||||
// UpdateDatabaseDdlOperation returns a new UpdateDatabaseDdlOperation from a given name.
|
||||
// The name must be that of a previously created UpdateDatabaseDdlOperation, possibly from a different process.
|
||||
func (c *DatabaseAdminClient) UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation {
|
||||
return &UpdateDatabaseDdlOperation{
|
||||
lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
|
||||
}
|
||||
}
|
||||
|
||||
// Wait blocks until the long-running operation is completed, returning any error encountered.
|
||||
//
|
||||
// See documentation of Poll for error-handling information.
|
||||
func (op *EmptyOperation) Wait(ctx context.Context) error {
|
||||
return op.lro.Wait(ctx, nil)
|
||||
func (op *UpdateDatabaseDdlOperation) Wait(ctx context.Context, opts ...gax.CallOption) error {
|
||||
return op.lro.Wait(ctx, nil, opts...)
|
||||
}
|
||||
|
||||
// Poll fetches the latest state of the long-running operation.
|
||||
@@ -503,15 +515,15 @@ func (op *EmptyOperation) Wait(ctx context.Context) error {
|
||||
// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
|
||||
// the operation has completed with failure, the error is returned and op.Done will return true.
|
||||
// If Poll succeeds and the operation has completed successfully, op.Done will return true.
|
||||
func (op *EmptyOperation) Poll(ctx context.Context) error {
|
||||
return op.lro.Poll(ctx, nil)
|
||||
func (op *UpdateDatabaseDdlOperation) Poll(ctx context.Context, opts ...gax.CallOption) error {
|
||||
return op.lro.Poll(ctx, nil, opts...)
|
||||
}
|
||||
|
||||
// Metadata returns metadata associated with the long-running operation.
|
||||
// Metadata itself does not contact the server, but Poll does.
|
||||
// To get the latest metadata, call this method after a successful call to Poll.
|
||||
// If the metadata is not available, the returned metadata and error are both nil.
|
||||
func (op *EmptyOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error) {
|
||||
func (op *UpdateDatabaseDdlOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error) {
|
||||
var meta databasepb.UpdateDatabaseDdlMetadata
|
||||
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
|
||||
return nil, nil
|
||||
@@ -522,12 +534,12 @@ func (op *EmptyOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, err
|
||||
}
|
||||
|
||||
// Done reports whether the long-running operation has completed.
|
||||
func (op *EmptyOperation) Done() bool {
|
||||
func (op *UpdateDatabaseDdlOperation) Done() bool {
|
||||
return op.lro.Done()
|
||||
}
|
||||
|
||||
// Name returns the name of the long-running operation.
|
||||
// The name is assigned by the server and is unique within the service from which the operation is created.
|
||||
func (op *EmptyOperation) Name() string {
|
||||
func (op *UpdateDatabaseDdlOperation) Name() string {
|
||||
return op.lro.Name()
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-1
@@ -19,6 +19,7 @@ package database_test
|
||||
import (
|
||||
"cloud.google.com/go/spanner/admin/database/apiv1"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
iampb "google.golang.org/genproto/googleapis/iam/v1"
|
||||
databasepb "google.golang.org/genproto/googleapis/spanner/admin/database/v1"
|
||||
)
|
||||
@@ -46,9 +47,11 @@ func ExampleDatabaseAdminClient_ListDatabases() {
|
||||
it := c.ListDatabases(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
|
||||
+14
-5
@@ -15,7 +15,7 @@
|
||||
// AUTO-GENERATED CODE. DO NOT EDIT.
|
||||
|
||||
// Package database is an experimental, auto-generated package for the
|
||||
// database API.
|
||||
// Cloud Spanner Database Admin API.
|
||||
//
|
||||
package database // import "cloud.google.com/go/spanner/admin/database/apiv1"
|
||||
|
||||
@@ -24,9 +24,18 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func insertXGoog(ctx context.Context, val string) context.Context {
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
func insertXGoog(ctx context.Context, val []string) context.Context {
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
md = md.Copy()
|
||||
md["x-goog-api-client"] = []string{val}
|
||||
return metadata.NewContext(ctx, md)
|
||||
md["x-goog-api-client"] = val
|
||||
return metadata.NewOutgoingContext(ctx, md)
|
||||
}
|
||||
|
||||
// DefaultAuthScopes reports the authentication scopes required
|
||||
// by this package.
|
||||
func DefaultAuthScopes() []string {
|
||||
return []string{
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/spanner.admin",
|
||||
}
|
||||
}
|
||||
|
||||
+96
-38
@@ -17,7 +17,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||
emptypb "github.com/golang/protobuf/ptypes/empty"
|
||||
iampb "google.golang.org/genproto/googleapis/iam/v1"
|
||||
longrunningpb "google.golang.org/genproto/googleapis/longrunning"
|
||||
databasepb "google.golang.org/genproto/googleapis/spanner/admin/database/v1"
|
||||
@@ -25,10 +25,12 @@ import (
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -38,6 +40,8 @@ import (
|
||||
status "google.golang.org/genproto/googleapis/rpc/status"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
gstatus "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var _ = io.EOF
|
||||
@@ -59,7 +63,11 @@ type mockDatabaseAdminServer struct {
|
||||
resps []proto.Message
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) ListDatabases(_ context.Context, req *databasepb.ListDatabasesRequest) (*databasepb.ListDatabasesResponse, error) {
|
||||
func (s *mockDatabaseAdminServer) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest) (*databasepb.ListDatabasesResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -67,7 +75,11 @@ func (s *mockDatabaseAdminServer) ListDatabases(_ context.Context, req *database
|
||||
return s.resps[0].(*databasepb.ListDatabasesResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) CreateDatabase(_ context.Context, req *databasepb.CreateDatabaseRequest) (*longrunningpb.Operation, error) {
|
||||
func (s *mockDatabaseAdminServer) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest) (*longrunningpb.Operation, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -75,7 +87,11 @@ func (s *mockDatabaseAdminServer) CreateDatabase(_ context.Context, req *databas
|
||||
return s.resps[0].(*longrunningpb.Operation), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) GetDatabase(_ context.Context, req *databasepb.GetDatabaseRequest) (*databasepb.Database, error) {
|
||||
func (s *mockDatabaseAdminServer) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest) (*databasepb.Database, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -83,7 +99,11 @@ func (s *mockDatabaseAdminServer) GetDatabase(_ context.Context, req *databasepb
|
||||
return s.resps[0].(*databasepb.Database), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) UpdateDatabaseDdl(_ context.Context, req *databasepb.UpdateDatabaseDdlRequest) (*longrunningpb.Operation, error) {
|
||||
func (s *mockDatabaseAdminServer) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest) (*longrunningpb.Operation, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -91,15 +111,23 @@ func (s *mockDatabaseAdminServer) UpdateDatabaseDdl(_ context.Context, req *data
|
||||
return s.resps[0].(*longrunningpb.Operation), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) DropDatabase(_ context.Context, req *databasepb.DropDatabaseRequest) (*google_protobuf.Empty, error) {
|
||||
func (s *mockDatabaseAdminServer) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest) (*emptypb.Empty, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
}
|
||||
return s.resps[0].(*google_protobuf.Empty), nil
|
||||
return s.resps[0].(*emptypb.Empty), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) GetDatabaseDdl(_ context.Context, req *databasepb.GetDatabaseDdlRequest) (*databasepb.GetDatabaseDdlResponse, error) {
|
||||
func (s *mockDatabaseAdminServer) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest) (*databasepb.GetDatabaseDdlResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -107,7 +135,11 @@ func (s *mockDatabaseAdminServer) GetDatabaseDdl(_ context.Context, req *databas
|
||||
return s.resps[0].(*databasepb.GetDatabaseDdlResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) SetIamPolicy(_ context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
func (s *mockDatabaseAdminServer) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -115,7 +147,11 @@ func (s *mockDatabaseAdminServer) SetIamPolicy(_ context.Context, req *iampb.Set
|
||||
return s.resps[0].(*iampb.Policy), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) GetIamPolicy(_ context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
func (s *mockDatabaseAdminServer) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -123,7 +159,11 @@ func (s *mockDatabaseAdminServer) GetIamPolicy(_ context.Context, req *iampb.Get
|
||||
return s.resps[0].(*iampb.Policy), nil
|
||||
}
|
||||
|
||||
func (s *mockDatabaseAdminServer) TestIamPermissions(_ context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error) {
|
||||
func (s *mockDatabaseAdminServer) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -210,8 +250,8 @@ func TestDatabaseAdminListDatabases(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminListDatabasesError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = DatabaseAdminInstancePath("[PROJECT]", "[INSTANCE]")
|
||||
var request = &databasepb.ListDatabasesRequest{
|
||||
@@ -225,7 +265,9 @@ func TestDatabaseAdminListDatabasesError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListDatabases(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -281,7 +323,7 @@ func TestDatabaseAdminCreateDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminCreateDatabaseError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = nil
|
||||
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
|
||||
Name: "longrunning-test",
|
||||
@@ -312,7 +354,9 @@ func TestDatabaseAdminCreateDatabaseError(t *testing.T) {
|
||||
}
|
||||
resp, err := respLRO.Wait(context.Background())
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -354,8 +398,8 @@ func TestDatabaseAdminGetDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminGetDatabaseError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedName string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var request = &databasepb.GetDatabaseRequest{
|
||||
@@ -369,13 +413,15 @@ func TestDatabaseAdminGetDatabaseError(t *testing.T) {
|
||||
|
||||
resp, err := c.GetDatabase(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
}
|
||||
func TestDatabaseAdminUpdateDatabaseDdl(t *testing.T) {
|
||||
var expectedResponse *google_protobuf.Empty = &google_protobuf.Empty{}
|
||||
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
|
||||
|
||||
mockDatabaseAdmin.err = nil
|
||||
mockDatabaseAdmin.reqs = nil
|
||||
@@ -419,7 +465,7 @@ func TestDatabaseAdminUpdateDatabaseDdl(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminUpdateDatabaseDdlError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = nil
|
||||
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
|
||||
Name: "longrunning-test",
|
||||
@@ -450,12 +496,14 @@ func TestDatabaseAdminUpdateDatabaseDdlError(t *testing.T) {
|
||||
}
|
||||
err = respLRO.Wait(context.Background())
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
}
|
||||
func TestDatabaseAdminDropDatabase(t *testing.T) {
|
||||
var expectedResponse *google_protobuf.Empty = &google_protobuf.Empty{}
|
||||
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
|
||||
|
||||
mockDatabaseAdmin.err = nil
|
||||
mockDatabaseAdmin.reqs = nil
|
||||
@@ -485,8 +533,8 @@ func TestDatabaseAdminDropDatabase(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminDropDatabaseError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var request = &databasepb.DropDatabaseRequest{
|
||||
@@ -500,7 +548,9 @@ func TestDatabaseAdminDropDatabaseError(t *testing.T) {
|
||||
|
||||
err = c.DropDatabase(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
}
|
||||
@@ -538,8 +588,8 @@ func TestDatabaseAdminGetDatabaseDdl(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminGetDatabaseDdlError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var request = &databasepb.GetDatabaseDdlRequest{
|
||||
@@ -553,7 +603,9 @@ func TestDatabaseAdminGetDatabaseDdlError(t *testing.T) {
|
||||
|
||||
resp, err := c.GetDatabaseDdl(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -599,8 +651,8 @@ func TestDatabaseAdminSetIamPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminSetIamPolicyError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var policy *iampb.Policy = &iampb.Policy{}
|
||||
@@ -616,7 +668,9 @@ func TestDatabaseAdminSetIamPolicyError(t *testing.T) {
|
||||
|
||||
resp, err := c.SetIamPolicy(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -660,8 +714,8 @@ func TestDatabaseAdminGetIamPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminGetIamPolicyError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var request = &iampb.GetIamPolicyRequest{
|
||||
@@ -675,7 +729,9 @@ func TestDatabaseAdminGetIamPolicyError(t *testing.T) {
|
||||
|
||||
resp, err := c.GetIamPolicy(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -716,8 +772,8 @@ func TestDatabaseAdminTestIamPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDatabaseAdminTestIamPermissionsError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockDatabaseAdmin.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
|
||||
var permissions []string = nil
|
||||
@@ -733,7 +789,9 @@ func TestDatabaseAdminTestIamPermissionsError(t *testing.T) {
|
||||
|
||||
resp, err := c.TestIamPermissions(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
|
||||
Reference in New Issue
Block a user