Vendor dependencies for GCS

This commit is contained in:
Alexander Neumann
2017-08-05 20:17:15 +02:00
parent ba75a3884c
commit 8ca6a9a240
1228 changed files with 1769186 additions and 1 deletions

View File

@@ -0,0 +1,545 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package database
import (
"math"
"time"
"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"
"google.golang.org/api/option"
"google.golang.org/api/transport"
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"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
var (
databaseAdminInstancePathTemplate = gax.MustCompilePathTemplate("projects/{project}/instances/{instance}")
databaseAdminDatabasePathTemplate = gax.MustCompilePathTemplate("projects/{project}/instances/{instance}/databases/{database}")
)
// DatabaseAdminCallOptions contains the retry settings for each method of DatabaseAdminClient.
type DatabaseAdminCallOptions struct {
ListDatabases []gax.CallOption
CreateDatabase []gax.CallOption
GetDatabase []gax.CallOption
UpdateDatabaseDdl []gax.CallOption
DropDatabase []gax.CallOption
GetDatabaseDdl []gax.CallOption
SetIamPolicy []gax.CallOption
GetIamPolicy []gax.CallOption
TestIamPermissions []gax.CallOption
}
func defaultDatabaseAdminClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("spanner.googleapis.com:443"),
option.WithScopes(DefaultAuthScopes()...),
}
}
func defaultDatabaseAdminCallOptions() *DatabaseAdminCallOptions {
retry := map[[2]string][]gax.CallOption{
{"default", "idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.DeadlineExceeded,
codes.Unavailable,
}, gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 32000 * time.Millisecond,
Multiplier: 1.3,
})
}),
},
}
return &DatabaseAdminCallOptions{
ListDatabases: retry[[2]string{"default", "idempotent"}],
CreateDatabase: retry[[2]string{"default", "non_idempotent"}],
GetDatabase: retry[[2]string{"default", "idempotent"}],
UpdateDatabaseDdl: retry[[2]string{"default", "idempotent"}],
DropDatabase: retry[[2]string{"default", "idempotent"}],
GetDatabaseDdl: retry[[2]string{"default", "idempotent"}],
SetIamPolicy: retry[[2]string{"default", "non_idempotent"}],
GetIamPolicy: retry[[2]string{"default", "idempotent"}],
TestIamPermissions: retry[[2]string{"default", "non_idempotent"}],
}
}
// DatabaseAdminClient is a client for interacting with Cloud Spanner Database Admin API.
type DatabaseAdminClient struct {
// The connection to the service.
conn *grpc.ClientConn
// 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
}
// NewDatabaseAdminClient creates a new database admin client.
//
// Cloud Spanner Database Admin API
//
// The Cloud Spanner Database Admin API can be used to create, drop, and
// list databases. It also enables updating the schema of pre-existing
// databases.
func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error) {
conn, err := transport.DialGRPC(ctx, append(defaultDatabaseAdminClientOptions(), opts...)...)
if err != nil {
return nil, err
}
c := &DatabaseAdminClient{
conn: conn,
CallOptions: defaultDatabaseAdminCallOptions(),
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
}
// Connection returns the client's connection to the API service.
func (c *DatabaseAdminClient) Connection() *grpc.ClientConn {
return c.conn
}
// Close closes the connection to the API service. The user should invoke this when
// the client is no longer required.
func (c *DatabaseAdminClient) Close() error {
return c.conn.Close()
}
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// 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", grpc.Version)
c.xGoogHeader = []string{gax.XGoogHeader(kv...)}
}
// DatabaseAdminInstancePath returns the path for the instance resource.
func DatabaseAdminInstancePath(project, instance string) string {
path, err := databaseAdminInstancePathTemplate.Render(map[string]string{
"project": project,
"instance": instance,
})
if err != nil {
panic(err)
}
return path
}
// DatabaseAdminDatabasePath returns the path for the database resource.
func DatabaseAdminDatabasePath(project, instance, database string) string {
path, err := databaseAdminDatabasePathTemplate.Render(map[string]string{
"project": project,
"instance": instance,
"database": database,
})
if err != nil {
panic(err)
}
return path
}
// ListDatabases lists Cloud Spanner databases.
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
req.PageToken = pageToken
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.ListDatabases(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, "", err
}
return resp.Databases, resp.NextPageToken, nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
return it
}
// CreateDatabase creates a new Cloud Spanner database and starts to prepare it for serving.
// The returned [long-running operation][google.longrunning.Operation] will
// have a name of the format `<database_name>/operations/<operation_id>` and
// can be used to track preparation of the database. The
// [metadata][google.longrunning.Operation.metadata] field type is
// [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, 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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.CreateDatabase(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
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, 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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.GetDatabase(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// UpdateDatabaseDdl updates the schema of a Cloud Spanner database by
// creating/altering/dropping tables, columns, indexes, etc. The returned
// [long-running operation][google.longrunning.Operation] will have a name of
// the format `<database_name>/operations/<operation_id>` and can be used to
// 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, 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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.UpdateDatabaseDdl(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
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, opts ...gax.CallOption) error {
ctx = insertXGoog(ctx, c.xGoogHeader)
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, settings.GRPC...)
return err
}, 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, 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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.GetDatabaseDdl(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// SetIamPolicy sets the access control policy on a database resource. Replaces any
// existing policy.
//
// Authorization requires `spanner.databases.setIamPolicy` permission on
// [resource][google.iam.v1.SetIamPolicyRequest.resource].
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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.SetIamPolicy(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// GetIamPolicy gets the access control policy for a database resource. Returns an empty
// policy if a database exists but does not have a policy set.
//
// Authorization requires `spanner.databases.getIamPolicy` permission on
// [resource][google.iam.v1.GetIamPolicyRequest.resource].
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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.GetIamPolicy(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// TestIamPermissions returns permissions that the caller has on the specified database resource.
//
// Attempting this RPC on a non-existent Cloud Spanner database will result in
// 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, 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, settings gax.CallSettings) error {
var err error
resp, err = c.databaseAdminClient.TestIamPermissions(ctx, req, settings.GRPC...)
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
// DatabaseIterator manages a stream of *databasepb.Database.
type DatabaseIterator struct {
items []*databasepb.Database
pageInfo *iterator.PageInfo
nextFunc func() error
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*databasepb.Database, nextPageToken string, err error)
}
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
func (it *DatabaseIterator) PageInfo() *iterator.PageInfo {
return it.pageInfo
}
// Next returns the next result. Its second return value is iterator.Done if there are no more
// results. Once Next returns Done, all subsequent calls will return Done.
func (it *DatabaseIterator) Next() (*databasepb.Database, error) {
var item *databasepb.Database
if err := it.nextFunc(); err != nil {
return item, err
}
item = it.items[0]
it.items = it.items[1:]
return item, nil
}
func (it *DatabaseIterator) bufLen() int {
return len(it.items)
}
func (it *DatabaseIterator) takeBuf() interface{} {
b := it.items
it.items = nil
return b
}
// CreateDatabaseOperation manages a long-running operation from CreateDatabase.
type CreateDatabaseOperation struct {
lro *longrunning.Operation
}
// 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 *CreateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
var resp databasepb.Database
if err := op.lro.Wait(ctx, &resp, opts...); err != nil {
return nil, err
}
return &resp, nil
}
// Poll fetches the latest state of the long-running operation.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// 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, 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 *CreateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error) {
var resp databasepb.Database
if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
return nil, err
}
if !op.Done() {
return nil, nil
}
return &resp, nil
}
// 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 *CreateDatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error) {
var meta databasepb.CreateDatabaseMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
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 *CreateDatabaseOperation) Name() string {
return op.lro.Name()
}
// UpdateDatabaseDdlOperation manages a long-running operation from UpdateDatabaseDdl.
type UpdateDatabaseDdlOperation struct {
lro *longrunning.Operation
}
// 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 *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.
//
// Poll also fetches the latest metadata, which can be retrieved by Metadata.
//
// 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 *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 *UpdateDatabaseDdlOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error) {
var meta databasepb.UpdateDatabaseDdlMetadata
if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
return nil, nil
} else if err != nil {
return nil, err
}
return &meta, nil
}
// Done reports whether the long-running operation has completed.
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 *UpdateDatabaseDdlOperation) Name() string {
return op.lro.Name()
}

View File

@@ -0,0 +1,207 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
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"
)
func ExampleNewDatabaseAdminClient() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use client.
_ = c
}
func ExampleDatabaseAdminClient_ListDatabases() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.ListDatabasesRequest{
// TODO: Fill request struct fields.
}
it := c.ListDatabases(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
}
func ExampleDatabaseAdminClient_CreateDatabase() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.CreateDatabaseRequest{
// TODO: Fill request struct fields.
}
op, err := c.CreateDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleDatabaseAdminClient_GetDatabase() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.GetDatabaseRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleDatabaseAdminClient_UpdateDatabaseDdl() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.UpdateDatabaseDdlRequest{
// TODO: Fill request struct fields.
}
op, err := c.UpdateDatabaseDdl(ctx, req)
if err != nil {
// TODO: Handle error.
}
err = op.Wait(ctx)
// TODO: Handle error.
}
func ExampleDatabaseAdminClient_DropDatabase() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.DropDatabaseRequest{
// TODO: Fill request struct fields.
}
err = c.DropDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func ExampleDatabaseAdminClient_GetDatabaseDdl() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &databasepb.GetDatabaseDdlRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetDatabaseDdl(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleDatabaseAdminClient_SetIamPolicy() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &iampb.SetIamPolicyRequest{
// TODO: Fill request struct fields.
}
resp, err := c.SetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleDatabaseAdminClient_GetIamPolicy() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &iampb.GetIamPolicyRequest{
// TODO: Fill request struct fields.
}
resp, err := c.GetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func ExampleDatabaseAdminClient_TestIamPermissions() {
ctx := context.Background()
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
req := &iampb.TestIamPermissionsRequest{
// TODO: Fill request struct fields.
}
resp, err := c.TestIamPermissions(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}

View File

@@ -0,0 +1,41 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
// Package database is an experimental, auto-generated package for the
// Cloud Spanner Database Admin API.
//
package database // import "cloud.google.com/go/spanner/admin/database/apiv1"
import (
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
)
func insertXGoog(ctx context.Context, val []string) context.Context {
md, _ := metadata.FromOutgoingContext(ctx)
md = md.Copy()
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",
}
}

View File

@@ -0,0 +1,798 @@
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// AUTO-GENERATED CODE. DO NOT EDIT.
package database
import (
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"
)
import (
"flag"
"fmt"
"io"
"log"
"net"
"os"
"strings"
"testing"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"golang.org/x/net/context"
"google.golang.org/api/option"
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
var _ = ptypes.MarshalAny
var _ status.Status
type mockDatabaseAdminServer struct {
// Embed for forward compatibility.
// Tests will keep working if more methods are added
// in the future.
databasepb.DatabaseAdminServer
reqs []proto.Message
// If set, all calls return this error.
err error
// responses to return if err == nil
resps []proto.Message
}
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
}
return s.resps[0].(*databasepb.ListDatabasesResponse), nil
}
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
}
return s.resps[0].(*longrunningpb.Operation), nil
}
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
}
return s.resps[0].(*databasepb.Database), nil
}
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
}
return s.resps[0].(*longrunningpb.Operation), nil
}
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].(*emptypb.Empty), nil
}
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
}
return s.resps[0].(*databasepb.GetDatabaseDdlResponse), nil
}
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
}
return s.resps[0].(*iampb.Policy), nil
}
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
}
return s.resps[0].(*iampb.Policy), nil
}
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
}
return s.resps[0].(*iampb.TestIamPermissionsResponse), nil
}
// clientOpt is the option tests should use to connect to the test server.
// It is initialized by TestMain.
var clientOpt option.ClientOption
var (
mockDatabaseAdmin mockDatabaseAdminServer
)
func TestMain(m *testing.M) {
flag.Parse()
serv := grpc.NewServer()
databasepb.RegisterDatabaseAdminServer(serv, &mockDatabaseAdmin)
lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
log.Fatal(err)
}
go serv.Serve(lis)
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
clientOpt = option.WithGRPCConn(conn)
os.Exit(m.Run())
}
func TestDatabaseAdminListDatabases(t *testing.T) {
var nextPageToken string = ""
var databasesElement *databasepb.Database = &databasepb.Database{}
var databases = []*databasepb.Database{databasesElement}
var expectedResponse = &databasepb.ListDatabasesResponse{
NextPageToken: nextPageToken,
Databases: databases,
}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedParent string = DatabaseAdminInstancePath("[PROJECT]", "[INSTANCE]")
var request = &databasepb.ListDatabasesRequest{
Parent: formattedParent,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.ListDatabases(context.Background(), request).Next()
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
want := (interface{})(expectedResponse.Databases[0])
got := (interface{})(resp)
var ok bool
switch want := (want).(type) {
case proto.Message:
ok = proto.Equal(want, got.(proto.Message))
default:
ok = want == got
}
if !ok {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminListDatabasesError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedParent string = DatabaseAdminInstancePath("[PROJECT]", "[INSTANCE]")
var request = &databasepb.ListDatabasesRequest{
Parent: formattedParent,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.ListDatabases(context.Background(), request).Next()
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 TestDatabaseAdminCreateDatabase(t *testing.T) {
var name string = "name3373707"
var expectedResponse = &databasepb.Database{
Name: name,
}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
any, err := ptypes.MarshalAny(expectedResponse)
if err != nil {
t.Fatal(err)
}
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
Name: "longrunning-test",
Done: true,
Result: &longrunningpb.Operation_Response{Response: any},
})
var formattedParent string = DatabaseAdminInstancePath("[PROJECT]", "[INSTANCE]")
var createStatement string = "createStatement552974828"
var request = &databasepb.CreateDatabaseRequest{
Parent: formattedParent,
CreateStatement: createStatement,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
respLRO, err := c.CreateDatabase(context.Background(), request)
if err != nil {
t.Fatal(err)
}
resp, err := respLRO.Wait(context.Background())
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminCreateDatabaseError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
Name: "longrunning-test",
Done: true,
Result: &longrunningpb.Operation_Error{
Error: &status.Status{
Code: int32(errCode),
Message: "test error",
},
},
})
var formattedParent string = DatabaseAdminInstancePath("[PROJECT]", "[INSTANCE]")
var createStatement string = "createStatement552974828"
var request = &databasepb.CreateDatabaseRequest{
Parent: formattedParent,
CreateStatement: createStatement,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
respLRO, err := c.CreateDatabase(context.Background(), request)
if err != nil {
t.Fatal(err)
}
resp, err := respLRO.Wait(context.Background())
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 TestDatabaseAdminGetDatabase(t *testing.T) {
var name2 string = "name2-1052831874"
var expectedResponse = &databasepb.Database{
Name: name2,
}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedName string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.GetDatabaseRequest{
Name: formattedName,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetDatabase(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminGetDatabaseError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedName string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.GetDatabaseRequest{
Name: formattedName,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetDatabase(context.Background(), request)
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 *emptypb.Empty = &emptypb.Empty{}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
any, err := ptypes.MarshalAny(expectedResponse)
if err != nil {
t.Fatal(err)
}
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
Name: "longrunning-test",
Done: true,
Result: &longrunningpb.Operation_Response{Response: any},
})
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var statements []string = nil
var request = &databasepb.UpdateDatabaseDdlRequest{
Database: formattedDatabase,
Statements: statements,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
respLRO, err := c.UpdateDatabaseDdl(context.Background(), request)
if err != nil {
t.Fatal(err)
}
err = respLRO.Wait(context.Background())
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
}
func TestDatabaseAdminUpdateDatabaseDdlError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], &longrunningpb.Operation{
Name: "longrunning-test",
Done: true,
Result: &longrunningpb.Operation_Error{
Error: &status.Status{
Code: int32(errCode),
Message: "test error",
},
},
})
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var statements []string = nil
var request = &databasepb.UpdateDatabaseDdlRequest{
Database: formattedDatabase,
Statements: statements,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
respLRO, err := c.UpdateDatabaseDdl(context.Background(), request)
if err != nil {
t.Fatal(err)
}
err = respLRO.Wait(context.Background())
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 *emptypb.Empty = &emptypb.Empty{}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.DropDatabaseRequest{
Database: formattedDatabase,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.DropDatabase(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
}
func TestDatabaseAdminDropDatabaseError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.DropDatabaseRequest{
Database: formattedDatabase,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
err = c.DropDatabase(context.Background(), request)
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 TestDatabaseAdminGetDatabaseDdl(t *testing.T) {
var expectedResponse *databasepb.GetDatabaseDdlResponse = &databasepb.GetDatabaseDdlResponse{}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.GetDatabaseDdlRequest{
Database: formattedDatabase,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetDatabaseDdl(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminGetDatabaseDdlError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedDatabase string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &databasepb.GetDatabaseDdlRequest{
Database: formattedDatabase,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetDatabaseDdl(context.Background(), request)
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 TestDatabaseAdminSetIamPolicy(t *testing.T) {
var version int32 = 351608024
var etag []byte = []byte("21")
var expectedResponse = &iampb.Policy{
Version: version,
Etag: etag,
}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var policy *iampb.Policy = &iampb.Policy{}
var request = &iampb.SetIamPolicyRequest{
Resource: formattedResource,
Policy: policy,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.SetIamPolicy(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminSetIamPolicyError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var policy *iampb.Policy = &iampb.Policy{}
var request = &iampb.SetIamPolicyRequest{
Resource: formattedResource,
Policy: policy,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.SetIamPolicy(context.Background(), request)
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 TestDatabaseAdminGetIamPolicy(t *testing.T) {
var version int32 = 351608024
var etag []byte = []byte("21")
var expectedResponse = &iampb.Policy{
Version: version,
Etag: etag,
}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &iampb.GetIamPolicyRequest{
Resource: formattedResource,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetIamPolicy(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminGetIamPolicyError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var request = &iampb.GetIamPolicyRequest{
Resource: formattedResource,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.GetIamPolicy(context.Background(), request)
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 TestDatabaseAdminTestIamPermissions(t *testing.T) {
var expectedResponse *iampb.TestIamPermissionsResponse = &iampb.TestIamPermissionsResponse{}
mockDatabaseAdmin.err = nil
mockDatabaseAdmin.reqs = nil
mockDatabaseAdmin.resps = append(mockDatabaseAdmin.resps[:0], expectedResponse)
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var permissions []string = nil
var request = &iampb.TestIamPermissionsRequest{
Resource: formattedResource,
Permissions: permissions,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.TestIamPermissions(context.Background(), request)
if err != nil {
t.Fatal(err)
}
if want, got := request, mockDatabaseAdmin.reqs[0]; !proto.Equal(want, got) {
t.Errorf("wrong request %q, want %q", got, want)
}
if want, got := expectedResponse, resp; !proto.Equal(want, got) {
t.Errorf("wrong response %q, want %q)", got, want)
}
}
func TestDatabaseAdminTestIamPermissionsError(t *testing.T) {
errCode := codes.PermissionDenied
mockDatabaseAdmin.err = gstatus.Error(errCode, "test error")
var formattedResource string = DatabaseAdminDatabasePath("[PROJECT]", "[INSTANCE]", "[DATABASE]")
var permissions []string = nil
var request = &iampb.TestIamPermissionsRequest{
Resource: formattedResource,
Permissions: permissions,
}
c, err := NewDatabaseAdminClient(context.Background(), clientOpt)
if err != nil {
t.Fatal(err)
}
resp, err := c.TestIamPermissions(context.Background(), request)
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
}