|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223 |
- // Copyright 2018 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.
-
- // AUTO-GENERATED CODE. DO NOT EDIT.
-
- package admin
-
- import (
- emptypb "github.com/golang/protobuf/ptypes/empty"
- adminpb "google.golang.org/genproto/googleapis/iam/admin/v1"
- iampb "google.golang.org/genproto/googleapis/iam/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 mockIamServer struct {
- // Embed for forward compatibility.
- // Tests will keep working if more methods are added
- // in the future.
- adminpb.IAMServer
-
- reqs []proto.Message
-
- // If set, all calls return this error.
- err error
-
- // responses to return if err == nil
- resps []proto.Message
- }
-
- func (s *mockIamServer) ListServiceAccounts(ctx context.Context, req *adminpb.ListServiceAccountsRequest) (*adminpb.ListServiceAccountsResponse, 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].(*adminpb.ListServiceAccountsResponse), nil
- }
-
- func (s *mockIamServer) GetServiceAccount(ctx context.Context, req *adminpb.GetServiceAccountRequest) (*adminpb.ServiceAccount, 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].(*adminpb.ServiceAccount), nil
- }
-
- func (s *mockIamServer) CreateServiceAccount(ctx context.Context, req *adminpb.CreateServiceAccountRequest) (*adminpb.ServiceAccount, 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].(*adminpb.ServiceAccount), nil
- }
-
- func (s *mockIamServer) UpdateServiceAccount(ctx context.Context, req *adminpb.ServiceAccount) (*adminpb.ServiceAccount, 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].(*adminpb.ServiceAccount), nil
- }
-
- func (s *mockIamServer) DeleteServiceAccount(ctx context.Context, req *adminpb.DeleteServiceAccountRequest) (*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 *mockIamServer) ListServiceAccountKeys(ctx context.Context, req *adminpb.ListServiceAccountKeysRequest) (*adminpb.ListServiceAccountKeysResponse, 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].(*adminpb.ListServiceAccountKeysResponse), nil
- }
-
- func (s *mockIamServer) GetServiceAccountKey(ctx context.Context, req *adminpb.GetServiceAccountKeyRequest) (*adminpb.ServiceAccountKey, 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].(*adminpb.ServiceAccountKey), nil
- }
-
- func (s *mockIamServer) CreateServiceAccountKey(ctx context.Context, req *adminpb.CreateServiceAccountKeyRequest) (*adminpb.ServiceAccountKey, 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].(*adminpb.ServiceAccountKey), nil
- }
-
- func (s *mockIamServer) DeleteServiceAccountKey(ctx context.Context, req *adminpb.DeleteServiceAccountKeyRequest) (*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 *mockIamServer) SignBlob(ctx context.Context, req *adminpb.SignBlobRequest) (*adminpb.SignBlobResponse, 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].(*adminpb.SignBlobResponse), nil
- }
-
- func (s *mockIamServer) SignJwt(ctx context.Context, req *adminpb.SignJwtRequest) (*adminpb.SignJwtResponse, 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].(*adminpb.SignJwtResponse), nil
- }
-
- func (s *mockIamServer) 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 *mockIamServer) 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 *mockIamServer) 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
- }
-
- func (s *mockIamServer) QueryGrantableRoles(ctx context.Context, req *adminpb.QueryGrantableRolesRequest) (*adminpb.QueryGrantableRolesResponse, 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].(*adminpb.QueryGrantableRolesResponse), nil
- }
-
- // clientOpt is the option tests should use to connect to the test server.
- // It is initialized by TestMain.
- var clientOpt option.ClientOption
-
- var (
- mockIam mockIamServer
- )
-
- func TestMain(m *testing.M) {
- flag.Parse()
-
- serv := grpc.NewServer()
- adminpb.RegisterIAMServer(serv, &mockIam)
-
- 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 TestIamListServiceAccounts(t *testing.T) {
- var nextPageToken string = ""
- var accountsElement *adminpb.ServiceAccount = &adminpb.ServiceAccount{}
- var accounts = []*adminpb.ServiceAccount{accountsElement}
- var expectedResponse = &adminpb.ListServiceAccountsResponse{
- NextPageToken: nextPageToken,
- Accounts: accounts,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &adminpb.ListServiceAccountsRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListServiceAccounts(context.Background(), request).Next()
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- want := (interface{})(expectedResponse.Accounts[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 TestIamListServiceAccountsError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var request = &adminpb.ListServiceAccountsRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListServiceAccounts(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 TestIamGetServiceAccount(t *testing.T) {
- var name2 string = "name2-1052831874"
- var projectId string = "projectId-1969970175"
- var uniqueId string = "uniqueId-538310583"
- var email string = "email96619420"
- var displayName string = "displayName1615086568"
- var etag []byte = []byte("21")
- var oauth2ClientId string = "oauth2ClientId-1833466037"
- var expectedResponse = &adminpb.ServiceAccount{
- Name: name2,
- ProjectId: projectId,
- UniqueId: uniqueId,
- Email: email,
- DisplayName: displayName,
- Etag: etag,
- Oauth2ClientId: oauth2ClientId,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.GetServiceAccountRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetServiceAccount(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamGetServiceAccountError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.GetServiceAccountRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetServiceAccount(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 TestIamCreateServiceAccount(t *testing.T) {
- var name2 string = "name2-1052831874"
- var projectId string = "projectId-1969970175"
- var uniqueId string = "uniqueId-538310583"
- var email string = "email96619420"
- var displayName string = "displayName1615086568"
- var etag []byte = []byte("21")
- var oauth2ClientId string = "oauth2ClientId-1833466037"
- var expectedResponse = &adminpb.ServiceAccount{
- Name: name2,
- ProjectId: projectId,
- UniqueId: uniqueId,
- Email: email,
- DisplayName: displayName,
- Etag: etag,
- Oauth2ClientId: oauth2ClientId,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var accountId string = "accountId-803333011"
- var request = &adminpb.CreateServiceAccountRequest{
- Name: formattedName,
- AccountId: accountId,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.CreateServiceAccount(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamCreateServiceAccountError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s", "[PROJECT]")
- var accountId string = "accountId-803333011"
- var request = &adminpb.CreateServiceAccountRequest{
- Name: formattedName,
- AccountId: accountId,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.CreateServiceAccount(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 TestIamUpdateServiceAccount(t *testing.T) {
- var name string = "name3373707"
- var projectId string = "projectId-1969970175"
- var uniqueId string = "uniqueId-538310583"
- var email string = "email96619420"
- var displayName string = "displayName1615086568"
- var etag2 []byte = []byte("-120")
- var oauth2ClientId string = "oauth2ClientId-1833466037"
- var expectedResponse = &adminpb.ServiceAccount{
- Name: name,
- ProjectId: projectId,
- UniqueId: uniqueId,
- Email: email,
- DisplayName: displayName,
- Etag: etag2,
- Oauth2ClientId: oauth2ClientId,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var etag []byte = []byte("21")
- var request = &adminpb.ServiceAccount{
- Etag: etag,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.UpdateServiceAccount(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamUpdateServiceAccountError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var etag []byte = []byte("21")
- var request = &adminpb.ServiceAccount{
- Etag: etag,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.UpdateServiceAccount(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 TestIamDeleteServiceAccount(t *testing.T) {
- var expectedResponse *emptypb.Empty = &emptypb.Empty{}
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.DeleteServiceAccountRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteServiceAccount(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- }
-
- func TestIamDeleteServiceAccountError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.DeleteServiceAccountRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteServiceAccount(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 TestIamListServiceAccountKeys(t *testing.T) {
- var expectedResponse *adminpb.ListServiceAccountKeysResponse = &adminpb.ListServiceAccountKeysResponse{}
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.ListServiceAccountKeysRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListServiceAccountKeys(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamListServiceAccountKeysError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.ListServiceAccountKeysRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.ListServiceAccountKeys(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 TestIamGetServiceAccountKey(t *testing.T) {
- var name2 string = "name2-1052831874"
- var privateKeyData []byte = []byte("-58")
- var publicKeyData []byte = []byte("-96")
- var expectedResponse = &adminpb.ServiceAccountKey{
- Name: name2,
- PrivateKeyData: privateKeyData,
- PublicKeyData: publicKeyData,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s/keys/%s", "[PROJECT]", "[SERVICE_ACCOUNT]", "[KEY]")
- var request = &adminpb.GetServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetServiceAccountKey(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamGetServiceAccountKeyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s/keys/%s", "[PROJECT]", "[SERVICE_ACCOUNT]", "[KEY]")
- var request = &adminpb.GetServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.GetServiceAccountKey(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 TestIamCreateServiceAccountKey(t *testing.T) {
- var name2 string = "name2-1052831874"
- var privateKeyData []byte = []byte("-58")
- var publicKeyData []byte = []byte("-96")
- var expectedResponse = &adminpb.ServiceAccountKey{
- Name: name2,
- PrivateKeyData: privateKeyData,
- PublicKeyData: publicKeyData,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.CreateServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.CreateServiceAccountKey(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamCreateServiceAccountKeyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &adminpb.CreateServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.CreateServiceAccountKey(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 TestIamDeleteServiceAccountKey(t *testing.T) {
- var expectedResponse *emptypb.Empty = &emptypb.Empty{}
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s/keys/%s", "[PROJECT]", "[SERVICE_ACCOUNT]", "[KEY]")
- var request = &adminpb.DeleteServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteServiceAccountKey(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.reqs[0]; !proto.Equal(want, got) {
- t.Errorf("wrong request %q, want %q", got, want)
- }
-
- }
-
- func TestIamDeleteServiceAccountKeyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s/keys/%s", "[PROJECT]", "[SERVICE_ACCOUNT]", "[KEY]")
- var request = &adminpb.DeleteServiceAccountKeyRequest{
- Name: formattedName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- err = c.DeleteServiceAccountKey(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 TestIamSignBlob(t *testing.T) {
- var keyId string = "keyId-1134673157"
- var signature []byte = []byte("-72")
- var expectedResponse = &adminpb.SignBlobResponse{
- KeyId: keyId,
- Signature: signature,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var bytesToSign []byte = []byte("45")
- var request = &adminpb.SignBlobRequest{
- Name: formattedName,
- BytesToSign: bytesToSign,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.SignBlob(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamSignBlobError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedName string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var bytesToSign []byte = []byte("45")
- var request = &adminpb.SignBlobRequest{
- Name: formattedName,
- BytesToSign: bytesToSign,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.SignBlob(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 TestIamGetIamPolicy(t *testing.T) {
- var version int32 = 351608024
- var etag []byte = []byte("21")
- var expectedResponse = &iampb.Policy{
- Version: version,
- Etag: etag,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &iampb.GetIamPolicyRequest{
- Resource: formattedResource,
- }
-
- c, err := NewIamClient(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, mockIam.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 TestIamGetIamPolicyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var request = &iampb.GetIamPolicyRequest{
- Resource: formattedResource,
- }
-
- c, err := NewIamClient(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 TestIamSetIamPolicy(t *testing.T) {
- var version int32 = 351608024
- var etag []byte = []byte("21")
- var expectedResponse = &iampb.Policy{
- Version: version,
- Etag: etag,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var policy *iampb.Policy = &iampb.Policy{}
- var request = &iampb.SetIamPolicyRequest{
- Resource: formattedResource,
- Policy: policy,
- }
-
- c, err := NewIamClient(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, mockIam.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 TestIamSetIamPolicyError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var policy *iampb.Policy = &iampb.Policy{}
- var request = &iampb.SetIamPolicyRequest{
- Resource: formattedResource,
- Policy: policy,
- }
-
- c, err := NewIamClient(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 TestIamTestIamPermissions(t *testing.T) {
- var expectedResponse *iampb.TestIamPermissionsResponse = &iampb.TestIamPermissionsResponse{}
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var permissions []string = nil
- var request = &iampb.TestIamPermissionsRequest{
- Resource: formattedResource,
- Permissions: permissions,
- }
-
- c, err := NewIamClient(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, mockIam.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 TestIamTestIamPermissionsError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var formattedResource string = fmt.Sprintf("projects/%s/serviceAccounts/%s", "[PROJECT]", "[SERVICE_ACCOUNT]")
- var permissions []string = nil
- var request = &iampb.TestIamPermissionsRequest{
- Resource: formattedResource,
- Permissions: permissions,
- }
-
- c, err := NewIamClient(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
- }
- func TestIamQueryGrantableRoles(t *testing.T) {
- var nextPageToken string = "nextPageToken-1530815211"
- var expectedResponse = &adminpb.QueryGrantableRolesResponse{
- NextPageToken: nextPageToken,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var fullResourceName string = "fullResourceName1300993644"
- var request = &adminpb.QueryGrantableRolesRequest{
- FullResourceName: fullResourceName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.QueryGrantableRoles(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamQueryGrantableRolesError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var fullResourceName string = "fullResourceName1300993644"
- var request = &adminpb.QueryGrantableRolesRequest{
- FullResourceName: fullResourceName,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.QueryGrantableRoles(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 TestIamSignJwt(t *testing.T) {
- var keyId string = "keyId-1134673157"
- var signedJwt string = "signedJwt-979546844"
- var expectedResponse = &adminpb.SignJwtResponse{
- KeyId: keyId,
- SignedJwt: signedJwt,
- }
-
- mockIam.err = nil
- mockIam.reqs = nil
-
- mockIam.resps = append(mockIam.resps[:0], expectedResponse)
-
- var name string = "name3373707"
- var payload string = "payload-786701938"
- var request = &adminpb.SignJwtRequest{
- Name: name,
- Payload: payload,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.SignJwt(context.Background(), request)
-
- if err != nil {
- t.Fatal(err)
- }
-
- if want, got := request, mockIam.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 TestIamSignJwtError(t *testing.T) {
- errCode := codes.PermissionDenied
- mockIam.err = gstatus.Error(errCode, "test error")
-
- var name string = "name3373707"
- var payload string = "payload-786701938"
- var request = &adminpb.SignJwtRequest{
- Name: name,
- Payload: payload,
- }
-
- c, err := NewIamClient(context.Background(), clientOpt)
- if err != nil {
- t.Fatal(err)
- }
-
- resp, err := c.SignJwt(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
- }
|