|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917 |
- // Copyright 2019 Google LLC
- //
- // 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
- //
- // https://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.
-
- // Code generated by gapic-generator. DO NOT EDIT.
-
- package instance
-
- import (
- emptypb "github.com/golang/protobuf/ptypes/empty"
- iampb "google.golang.org/genproto/googleapis/iam/v1"
- longrunningpb "google.golang.org/genproto/googleapis/longrunning"
- instancepb "google.golang.org/genproto/googleapis/spanner/admin/instance/v1"
- field_maskpb "google.golang.org/genproto/protobuf/field_mask"
- )
-
- import (
- "context"
- "flag"
- "fmt"
- "io"
- "log"
- "net"
- "os"
- "strings"
- "testing"
-
- "github.com/golang/protobuf/proto"
- "github.com/golang/protobuf/ptypes"
- "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 mockInstanceAdminServer struct {
- // Embed for forward compatibility.
- // Tests will keep working if more methods are added
- // in the future.
- instancepb.InstanceAdminServer
-
- reqs []proto.Message
-
- // If set, all calls return this error.
- err error
-
- // responses to return if err == nil
- resps []proto.Message
- }
-
- func (s *mockInstanceAdminServer) ListInstanceConfigs(ctx context.Context, req *instancepb.ListInstanceConfigsRequest) (*instancepb.ListInstanceConfigsResponse, 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].(*instancepb.ListInstanceConfigsResponse), nil
- }
-
- func (s *mockInstanceAdminServer) GetInstanceConfig(ctx context.Context, req *instancepb.GetInstanceConfigRequest) (*instancepb.InstanceConfig, 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].(*instancepb.InstanceConfig), nil
- }
-
- func (s *mockInstanceAdminServer) ListInstances(ctx context.Context, req *instancepb.ListInstancesRequest) (*instancepb.ListInstancesResponse, 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].(*instancepb.ListInstancesResponse), nil
- }
-
- func (s *mockInstanceAdminServer) GetInstance(ctx context.Context, req *instancepb.GetInstanceRequest) (*instancepb.Instance, 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].(*instancepb.Instance), nil
- }
-
- func (s *mockInstanceAdminServer) CreateInstance(ctx context.Context, req *instancepb.CreateInstanceRequest) (*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 *mockInstanceAdminServer) UpdateInstance(ctx context.Context, req *instancepb.UpdateInstanceRequest) (*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 *mockInstanceAdminServer) DeleteInstance(ctx context.Context, req *instancepb.DeleteInstanceRequest) (*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 *mockInstanceAdminServer) 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 *mockInstanceAdminServer) 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 *mockInstanceAdminServer) 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 (
- mockInstanceAdmin mockInstanceAdminServer
- )
-
- func TestMain(m *testing.M) {
- flag.Parse()
-
- serv := grpc.NewServer()
- instancepb.RegisterInstanceAdminServer(serv, &mockInstanceAdmin)
-
- 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 TestInstanceAdminListInstanceConfigs(t *testing.T) {
- var nextPageToken string = ""
- var instanceConfigsElement *instancepb.InstanceConfig = &instancepb.InstanceConfig{}
- var instanceConfigs = []*instancepb.InstanceConfig{instanceConfigsElement}
- var expectedResponse = &instancepb.ListInstanceConfigsResponse{
- NextPageToken: nextPageToken,
- InstanceConfigs: instanceConfigs,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &instancepb.ListInstanceConfigsRequest{
- Parent: formattedParent,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListInstanceConfigs(context.Background(), request).Next()
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockInstanceAdmin.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- want := (interface{})(expectedResponse.InstanceConfigs[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 TestInstanceAdminListInstanceConfigsError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &instancepb.ListInstanceConfigsRequest{
- Parent: formattedParent,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListInstanceConfigs(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 TestInstanceAdminGetInstanceConfig(t *testing.T) {
- var name2 string = "name2-1052831874"
- var displayName string = "displayName1615086568"
- var expectedResponse = &instancepb.InstanceConfig{
- Name: name2,
- DisplayName: displayName,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/instanceConfigs/%s", "[PROJECT]", "[INSTANCE_CONFIG]")
- var request = &instancepb.GetInstanceConfigRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetInstanceConfig(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockInstanceAdmin.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 TestInstanceAdminGetInstanceConfigError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/instanceConfigs/%s", "[PROJECT]", "[INSTANCE_CONFIG]")
- var request = &instancepb.GetInstanceConfigRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetInstanceConfig(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 TestInstanceAdminListInstances(t *testing.T) {
- var nextPageToken string = ""
- var instancesElement *instancepb.Instance = &instancepb.Instance{}
- var instances = []*instancepb.Instance{instancesElement}
- var expectedResponse = &instancepb.ListInstancesResponse{
- NextPageToken: nextPageToken,
- Instances: instances,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &instancepb.ListInstancesRequest{
- Parent: formattedParent,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListInstances(context.Background(), request).Next()
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockInstanceAdmin.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- want := (interface{})(expectedResponse.Instances[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 TestInstanceAdminListInstancesError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &instancepb.ListInstancesRequest{
- Parent: formattedParent,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListInstances(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 TestInstanceAdminGetInstance(t *testing.T) {
- var name2 string = "name2-1052831874"
- var config string = "config-1354792126"
- var displayName string = "displayName1615086568"
- var nodeCount int32 = 1539922066
- var expectedResponse = &instancepb.Instance{
- Name: name2,
- Config: config,
- DisplayName: displayName,
- NodeCount: nodeCount,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &instancepb.GetInstanceRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetInstance(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockInstanceAdmin.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 TestInstanceAdminGetInstanceError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &instancepb.GetInstanceRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetInstance(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 TestInstanceAdminCreateInstance(t *testing.T) {
- var name string = "name3373707"
- var config string = "config-1354792126"
- var displayName string = "displayName1615086568"
- var nodeCount int32 = 1539922066
- var expectedResponse = &instancepb.Instance{
- Name: name,
- Config: config,
- DisplayName: displayName,
- NodeCount: nodeCount,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- any, err := ptypes.MarshalAny(expectedResponse)
- if err != nil {
- t.Fatal(err)
- }
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], &longrunningpb.Operation{
- Name: "longrunning-test",
- Done: true,
- Result: &longrunningpb.Operation_Response{Response: any},
- })
-
- var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var instanceId string = "instanceId-2101995259"
- var instance *instancepb.Instance = &instancepb.Instance{}
- var request = &instancepb.CreateInstanceRequest{
- Parent: formattedParent,
- InstanceId: instanceId,
- Instance: instance,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- respLRO, err := c.CreateInstance(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, mockInstanceAdmin.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 TestInstanceAdminCreateInstanceError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.resps = append(mockInstanceAdmin.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 = fmt.Sprintf("projects/%s", "[PROJECT]")
- var instanceId string = "instanceId-2101995259"
- var instance *instancepb.Instance = &instancepb.Instance{}
- var request = &instancepb.CreateInstanceRequest{
- Parent: formattedParent,
- InstanceId: instanceId,
- Instance: instance,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- respLRO, err := c.CreateInstance(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 TestInstanceAdminUpdateInstance(t *testing.T) {
- var name string = "name3373707"
- var config string = "config-1354792126"
- var displayName string = "displayName1615086568"
- var nodeCount int32 = 1539922066
- var expectedResponse = &instancepb.Instance{
- Name: name,
- Config: config,
- DisplayName: displayName,
- NodeCount: nodeCount,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- any, err := ptypes.MarshalAny(expectedResponse)
- if err != nil {
- t.Fatal(err)
- }
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], &longrunningpb.Operation{
- Name: "longrunning-test",
- Done: true,
- Result: &longrunningpb.Operation_Response{Response: any},
- })
-
- var instance *instancepb.Instance = &instancepb.Instance{}
- var fieldMask *field_maskpb.FieldMask = &field_maskpb.FieldMask{}
- var request = &instancepb.UpdateInstanceRequest{
- Instance: instance,
- FieldMask: fieldMask,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- respLRO, err := c.UpdateInstance(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, mockInstanceAdmin.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 TestInstanceAdminUpdateInstanceError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], &longrunningpb.Operation{
- Name: "longrunning-test",
- Done: true,
- Result: &longrunningpb.Operation_Error{
- Error: &status.Status{
- Code: int32(errCode),
- Message: "test error",
- },
- },
- })
-
- var instance *instancepb.Instance = &instancepb.Instance{}
- var fieldMask *field_maskpb.FieldMask = &field_maskpb.FieldMask{}
- var request = &instancepb.UpdateInstanceRequest{
- Instance: instance,
- FieldMask: fieldMask,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- respLRO, err := c.UpdateInstance(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 TestInstanceAdminDeleteInstance(t *testing.T) {
- var expectedResponse *emptypb.Empty = &emptypb.Empty{}
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &instancepb.DeleteInstanceRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteInstance(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockInstanceAdmin.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- }
-
- func TestInstanceAdminDeleteInstanceError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &instancepb.DeleteInstanceRequest{
- Name: formattedName,
- }
-
- c, err := NewInstanceAdminClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteInstance(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 TestInstanceAdminSetIamPolicy(t *testing.T) {
- var version int32 = 351608024
- var etag []byte = []byte("21")
- var expectedResponse = &iampb.Policy{
- Version: version,
- Etag: etag,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var policy *iampb.Policy = &iampb.Policy{}
- var request = &iampb.SetIamPolicyRequest{
- Resource: formattedResource,
- Policy: policy,
- }
-
- c, err := NewInstanceAdminClient(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, mockInstanceAdmin.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 TestInstanceAdminSetIamPolicyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var policy *iampb.Policy = &iampb.Policy{}
- var request = &iampb.SetIamPolicyRequest{
- Resource: formattedResource,
- Policy: policy,
- }
-
- c, err := NewInstanceAdminClient(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 TestInstanceAdminGetIamPolicy(t *testing.T) {
- var version int32 = 351608024
- var etag []byte = []byte("21")
- var expectedResponse = &iampb.Policy{
- Version: version,
- Etag: etag,
- }
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &iampb.GetIamPolicyRequest{
- Resource: formattedResource,
- }
-
- c, err := NewInstanceAdminClient(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, mockInstanceAdmin.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 TestInstanceAdminGetIamPolicyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var request = &iampb.GetIamPolicyRequest{
- Resource: formattedResource,
- }
-
- c, err := NewInstanceAdminClient(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 TestInstanceAdminTestIamPermissions(t *testing.T) {
- var expectedResponse *iampb.TestIamPermissionsResponse = &iampb.TestIamPermissionsResponse{}
-
- mockInstanceAdmin.err = nil
- mockInstanceAdmin.reqs = nil
-
- mockInstanceAdmin.resps = append(mockInstanceAdmin.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var permissions []string = nil
- var request = &iampb.TestIamPermissionsRequest{
- Resource: formattedResource,
- Permissions: permissions,
- }
-
- c, err := NewInstanceAdminClient(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, mockInstanceAdmin.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 TestInstanceAdminTestIamPermissionsError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockInstanceAdmin.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/instances/%s", "[PROJECT]", "[INSTANCE]")
- var permissions []string = nil
- var request = &iampb.TestIamPermissionsRequest{
- Resource: formattedResource,
- Permissions: permissions,
- }
-
- c, err := NewInstanceAdminClient(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
- }
|