diff --git a/Makefile b/Makefile index e0baa1e..6b20a56 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,4 @@ mocks: go install github.com/vektra/mockery/v2@v2.34.2 mockery --srcpkg github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/organization_service --name=ClientService mockery --srcpkg github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/project_service --name=ClientService + mockery --srcpkg github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/iam_service --name=ClientService diff --git a/connect.go b/connect.go index 532aa00..90ad8a4 100644 --- a/connect.go +++ b/connect.go @@ -7,15 +7,16 @@ import ( "errors" "flag" "fmt" + "net/http" "strings" - hcprmm "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/models" - hcpvsm "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-service/stable/2020-11-25/models" - "github.com/hashicorp/cli" + hcpis "github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/iam_service" hcprmo "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/organization_service" hcprmp "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/project_service" + hcprmm "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/models" hcpvs "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-service/stable/2020-11-25/client/vault_service" + hcpvsm "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-service/stable/2020-11-25/models" "github.com/hashicorp/hcp-sdk-go/config" "github.com/hashicorp/hcp-sdk-go/httpclient" ) @@ -23,7 +24,7 @@ import ( var ( _ cli.Command = (*HCPConnectCommand)(nil) - ErrorProxyDisabled = errors.New("proxy is disabled") + ErrorProxyDisabled = fmt.Errorf("proxy is disabled") ) type HCPConnectCommand struct { @@ -39,6 +40,7 @@ type HCPConnectCommand struct { rmOrgClient hcprmo.ClientService vsClient hcpvs.ClientService rmProjClient hcprmp.ClientService + iamClient hcpis.ClientService } func (c *HCPConnectCommand) Help() string { @@ -71,12 +73,13 @@ func (c *HCPConnectCommand) Run(args []string) int { return 1 } - if err := c.setupClients(); err != nil { + err := c.setupClients() + if err != nil { c.Ui.Error(err.Error()) return 1 } - proxyAddr, err := c.getProxyAddr(c.rmOrgClient, c.rmProjClient, c.vsClient) + proxyAddr, err := c.getProxyAddr() if err != nil { if errors.Is(err, ErrorProxyDisabled) { c.Ui.Error("\nFailed to connect to HCP Vault Cluster: HTTP proxy feature not enabled.") @@ -97,48 +100,87 @@ func (c *HCPConnectCommand) Run(args []string) int { } func (c *HCPConnectCommand) setupClients() error { - var opts []config.HCPConfigOption - - if c.rmOrgClient == nil && c.rmProjClient == nil && c.vsClient == nil { - opts = []config.HCPConfigOption{config.FromEnv()} - - if c.flagClientID != "" && c.flagSecretID == "" { - return errors.New("secret-id is required when client-id is provided") - } else if c.flagSecretID != "" && c.flagClientID == "" { - return errors.New("client-id is required when secret-id is provided") - } else if c.flagClientID != "" && c.flagSecretID != "" { - opts = append(opts, config.WithClientCredentials(c.flagClientID, c.flagSecretID)) - opts = append(opts, config.WithoutBrowserLogin()) + opts := []config.HCPConfigOption{config.FromEnv()} + + if c.flagClientID != "" && c.flagSecretID == "" { + return fmt.Errorf("secret-id is required when client-id is provided") + } else if c.flagSecretID != "" && c.flagClientID == "" { + return fmt.Errorf("client-id is required when secret-id is provided") + } else if c.flagClientID != "" && c.flagSecretID != "" { + opts = append(opts, config.WithClientCredentials(c.flagClientID, c.flagSecretID)) + opts = append(opts, config.WithoutBrowserLogin()) + } + + cfg, err := config.NewHCPConfig(opts...) + if err != nil { + return fmt.Errorf("failed to connect to HCP: %w", err) + } + + hcpHttpClient, err := httpclient.New(httpclient.Config{HCPConfig: cfg}) + if err != nil { + return fmt.Errorf("failed to connect to HCP: %w", err) + } + + // client should only be pre-populated for testing + if c.iamClient == nil { + c.iamClient = hcpis.New(hcpHttpClient, nil) + } + + // verify token is valid + resp, err := c.iamClient.IamServiceGetCallerIdentity(hcpis.NewIamServiceGetCallerIdentityParams().WithDefaults(), nil) + if err != nil { + if identErr, ok := err.(*hcpis.IamServiceGetCallerIdentityDefault); ok && !identErr.IsCode(http.StatusUnauthorized) { + return fmt.Errorf("failed to get HCP caller identity: %w", err) } + } - cfg, err := config.NewHCPConfig(opts...) + // force re-auth in case where cached token is invalid + if resp == nil || resp.Payload == nil || resp.Payload.Principal == nil { + err = cfg.Logout() + if err != nil { + return fmt.Errorf("failed to erase HCP credentials cache: %w", err) + } + cfg, err = config.NewHCPConfig(opts...) if err != nil { - return errors.New(fmt.Sprintf("Failed to connect to HCP: %s", err)) + return fmt.Errorf("failed to connect to HCP: %w", err) } - hcpHttpClient, err := httpclient.New(httpclient.Config{HCPConfig: cfg}) + hcpHttpClient, err = httpclient.New(httpclient.Config{HCPConfig: cfg}) if err != nil { - return errors.New(fmt.Sprintf("Failed to connect to HCP: %s", err)) + return fmt.Errorf("failed to connect to HCP: %w", err) } + } + + // clients should only be pre-populated for testing + if c.iamClient == nil { + c.iamClient = hcpis.New(hcpHttpClient, nil) + } + if c.rmOrgClient == nil { c.rmOrgClient = hcprmo.New(hcpHttpClient, nil) - c.rmProjClient = hcprmp.New(hcpHttpClient, nil) + } + + if c.vsClient == nil { c.vsClient = hcpvs.New(hcpHttpClient, nil) } + if c.rmProjClient == nil { + c.rmProjClient = hcprmp.New(hcpHttpClient, nil) + } + return nil } -func (c *HCPConnectCommand) getProxyAddr(organizationClient hcprmo.ClientService, projectClient hcprmp.ClientService, clusterClient hcpvs.ClientService) (string, error) { +func (c *HCPConnectCommand) getProxyAddr() (string, error) { var err error var organizationID string if c.flagOrganizationID != "" { organizationID = c.flagOrganizationID } else { - organizationID, err = c.getOrganization(organizationClient) + organizationID, err = c.getOrganization() if err != nil { - return "", errors.New(fmt.Sprintf("Failed to get HCP organization information: %s", err)) + return "", fmt.Errorf("failed to get HCP organization information: %w", err) } } @@ -146,13 +188,13 @@ func (c *HCPConnectCommand) getProxyAddr(organizationClient hcprmo.ClientService if c.flagProjectID != "" { projectID = c.flagProjectID } else { - projectID, err = c.getProject(organizationID, projectClient) + projectID, err = c.getProject(organizationID) if err != nil { - return "", errors.New(fmt.Sprintf("Failed to get HCP project information: %s", err)) + return "", fmt.Errorf("failed to get HCP project information: %w", err) } } - proxyAddr, err := c.getCluster(organizationID, projectID, c.flagClusterID, clusterClient) + proxyAddr, err := c.getCluster(organizationID, projectID, c.flagClusterID) if err != nil { return "", err } @@ -175,15 +217,15 @@ func (c *HCPConnectCommand) Flags() *flag.FlagSet { return mainSet } -func (c *HCPConnectCommand) getOrganization(rmOrgClient hcprmo.ClientService) (organizationID string, err error) { - organizationsResp, err := rmOrgClient.OrganizationServiceList(hcprmo.NewOrganizationServiceListParams().WithDefaults(), nil) +func (c *HCPConnectCommand) getOrganization() (organizationID string, err error) { + organizationsResp, err := c.rmOrgClient.OrganizationServiceList(hcprmo.NewOrganizationServiceListParams().WithDefaults(), nil) switch { case err != nil: return "", err case organizationsResp.GetPayload() == nil: - return "", errors.New("payload is nil") + return "", fmt.Errorf("payload is nil") case len(organizationsResp.GetPayload().Organizations) < 1: - return "", errors.New("no organizations available") + return "", fmt.Errorf("no organizations available") case len(organizationsResp.GetPayload().Organizations) > 1: title := "Available organizations:" u := strings.Repeat("-", len(title)) @@ -203,33 +245,33 @@ func (c *HCPConnectCommand) getOrganization(rmOrgClient hcprmo.ClientService) (o } chosenOrg, ok := orgs[userInput] if !ok { - return "", errors.New(fmt.Sprintf("invalid HCP organization: %s", userInput)) + return "", fmt.Errorf("invalid HCP organization: %s", userInput) } return chosenOrg.ID, nil default: organization := organizationsResp.GetPayload().Organizations[0] if *organization.State != hcprmm.HashicorpCloudResourcemanagerOrganizationOrganizationStateACTIVE { - return "", errors.New("organization is not active") + return "", fmt.Errorf("organization is not active") } return organization.ID, nil } } -func (c *HCPConnectCommand) getProject(organizationID string, rmProjClient hcprmp.ClientService) (projectID string, err error) { +func (c *HCPConnectCommand) getProject(organizationID string) (projectID string, err error) { scopeType := "ORGANIZATION" projectListReq := hcprmp. NewProjectServiceListParams(). WithDefaults(). WithScopeType(&scopeType). WithScopeID(&organizationID) - projectResp, err := rmProjClient.ProjectServiceList(projectListReq, nil) + projectResp, err := c.rmProjClient.ProjectServiceList(projectListReq, nil) switch { case err != nil: return "", err case projectResp.GetPayload() == nil: - return "", errors.New("payload is nil") + return "", fmt.Errorf("payload is nil") case len(projectResp.GetPayload().Projects) < 1: - return "", errors.New("no projects available") + return "", fmt.Errorf("no projects available") case len(projectResp.GetPayload().Projects) > 1: title := "Available projects:" u := strings.Repeat("-", len(title)) @@ -249,21 +291,21 @@ func (c *HCPConnectCommand) getProject(organizationID string, rmProjClient hcprm } chosenProj, ok := projs[userInput] if !ok { - return "", errors.New(fmt.Sprintf("invalid HCP project: %s", userInput)) + return "", fmt.Errorf("invalid HCP project: %s", userInput) } return chosenProj.ID, nil default: project := projectResp.GetPayload().Projects[0] if *project.State != hcprmm.HashicorpCloudResourcemanagerProjectProjectStateACTIVE { - return "", errors.New("project is not active") + return "", fmt.Errorf("project is not active") } return project.ID, nil } } -func (c *HCPConnectCommand) getCluster(organizationID string, projectID string, clusterID string, vsClient hcpvs.ClientService) (proxyAddr string, err error) { +func (c *HCPConnectCommand) getCluster(organizationID string, projectID string, clusterID string) (proxyAddr string, err error) { if clusterID == "" { - return c.listClusters(organizationID, projectID, vsClient) + return c.listClusters(organizationID, projectID) } clusterGetReq := hcpvs.NewGetParams(). @@ -271,12 +313,12 @@ func (c *HCPConnectCommand) getCluster(organizationID string, projectID string, WithLocationOrganizationID(organizationID). WithLocationProjectID(projectID). WithClusterID(clusterID) - clusterResp, err := vsClient.Get(clusterGetReq, nil) + clusterResp, err := c.vsClient.Get(clusterGetReq, nil) switch { case err != nil: - return "", err + return "", fmt.Errorf("failed to get cluster %s: %s", clusterID, err) case clusterResp.GetPayload() == nil: - return "", errors.New("payload is nil") + return "", fmt.Errorf("payload is nil") default: cluster := clusterResp.GetPayload().Cluster @@ -293,21 +335,21 @@ func (c *HCPConnectCommand) getCluster(organizationID string, projectID string, } } -func (c *HCPConnectCommand) listClusters(organizationID string, projectID string, vsClient hcpvs.ClientService) (proxyAddr string, err error) { +func (c *HCPConnectCommand) listClusters(organizationID string, projectID string) (proxyAddr string, err error) { clusterListReq := hcpvs.NewListParams(). WithDefaults(). WithLocationOrganizationID(organizationID). WithLocationProjectID(projectID) // Purposely calling List instead of ListAll because we are only interested in HVD clusters. - clustersResp, err := vsClient.List(clusterListReq, nil) + clustersResp, err := c.vsClient.List(clusterListReq, nil) switch { case err != nil: return "", err case clustersResp.GetPayload() == nil: - return "", errors.New("payload is nil") + return "", fmt.Errorf("payload is nil") case len(clustersResp.GetPayload().Clusters) < 1: - return "", errors.New("no clusters available") + return "", fmt.Errorf("no clusters available") case len(clustersResp.GetPayload().Clusters) > 1: title := "Available clusters:" u := strings.Repeat("-", len(title)) @@ -330,7 +372,7 @@ func (c *HCPConnectCommand) listClusters(organizationID string, projectID string // set the cluster cluster, ok := clusters[userInput] if !ok { - return "", errors.New(fmt.Sprintf("invalid cluster: %s", userInput)) + return "", fmt.Errorf("invalid cluster: %s", userInput) } if *cluster.Config.NetworkConfig.HTTPProxyOption == hcpvsm.HashicorpCloudVault20201125HTTPProxyOptionDISABLED { return "", ErrorProxyDisabled @@ -345,11 +387,11 @@ func (c *HCPConnectCommand) listClusters(organizationID string, projectID string clusterState := *cluster.State if clusterState == hcpvsm.HashicorpCloudVault20201125ClusterStateLOCKED || clusterState == hcpvsm.HashicorpCloudVault20201125ClusterStateLOCKING { - return "", errors.New("cluster is locked") + return "", fmt.Errorf("cluster is locked") } else if clusterState == hcpvsm.HashicorpCloudVault20201125ClusterStateCREATING { - return "", errors.New("cluster is still being created") + return "", fmt.Errorf("cluster is still being created") } else if clusterState != hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING { - return "", errors.New("cluster is not running") + return "", fmt.Errorf("cluster is not running") } if *cluster.Config.NetworkConfig.HTTPProxyOption == hcpvsm.HashicorpCloudVault20201125HTTPProxyOptionDISABLED { diff --git a/connect_test.go b/connect_test.go index eff090f..3181e3d 100644 --- a/connect_test.go +++ b/connect_test.go @@ -4,17 +4,21 @@ package vaulthcplib import ( - "errors" + "fmt" "io" + "net/http" "testing" "github.com/hashicorp/cli" clustermocks "github.com/hashicorp/vault-hcp-lib/mocks/cluster" + iammocks "github.com/hashicorp/vault-hcp-lib/mocks/iam" orgmocks "github.com/hashicorp/vault-hcp-lib/mocks/organization" projmocks "github.com/hashicorp/vault-hcp-lib/mocks/project" "github.com/google/uuid" + hcpis "github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/iam_service" + iam_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/models" hcprmo "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/organization_service" hcprmp "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/client/project_service" "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/stable/2019-12-10/models" @@ -76,68 +80,151 @@ func Test_HCPConnect_FlagValidation(t *testing.T) { } func Test_HCPConnectCommand(t *testing.T) { - _, cmd := testHCPConnectCommand() - - mockRmOrgClient := orgmocks.NewClientService(t) - mockRmOrgClient. - On("OrganizationServiceList", mock.Anything, nil). - Return(&hcprmo.OrganizationServiceListOK{ - Payload: &models.HashicorpCloudResourcemanagerOrganizationListResponse{ - Organizations: []*models.HashicorpCloudResourcemanagerOrganization{ - { - ID: uuid.New().String(), - Name: "mock-organization-1", - State: models.NewHashicorpCloudResourcemanagerOrganizationOrganizationState( - models.HashicorpCloudResourcemanagerOrganizationOrganizationStateACTIVE, - ), + tests := map[string]struct { + getCallerIdentityResp *hcpis.IamServiceGetCallerIdentityOK + getCallerIdentityErr error + expectedResult int + expectedError string + }{ + "OK resp": { + getCallerIdentityResp: &hcpis.IamServiceGetCallerIdentityOK{ + Payload: &iam_models.HashicorpCloudIamGetCallerIdentityResponse{ + Principal: &iam_models.HashicorpCloudIamPrincipal{ + User: &iam_models.HashicorpCloudIamUserPrincipal{ + Email: "test@test.com", + FullName: "HCP Test", + ID: "test", + Subject: "test", + }, }, }, }, - }, nil) - - mockRmProjClient := projmocks.NewClientService(t) - mockRmProjClient. - On("ProjectServiceList", mock.Anything, nil). - Return(&hcprmp.ProjectServiceListOK{ - Payload: &models.HashicorpCloudResourcemanagerProjectListResponse{ - Projects: []*models.HashicorpCloudResourcemanagerProject{ - { - ID: uuid.New().String(), - Name: "mock-project-1", - State: models.NewHashicorpCloudResourcemanagerProjectProjectState( - models.HashicorpCloudResourcemanagerProjectProjectStateACTIVE, - ), - }, - }, + getCallerIdentityErr: nil, + expectedResult: 0, + expectedError: "", + }, + "no resp or error": { + getCallerIdentityResp: nil, + getCallerIdentityErr: nil, + expectedResult: 0, + expectedError: "", + }, + "error - unauthorized": { + getCallerIdentityResp: nil, + getCallerIdentityErr: hcpis.NewIamServiceGetCallerIdentityDefault(http.StatusUnauthorized), + expectedResult: 0, + expectedError: "", + }, + "error - server error": { + getCallerIdentityResp: nil, + getCallerIdentityErr: hcpis.NewIamServiceGetCallerIdentityDefault(http.StatusInternalServerError), + expectedResult: 1, + expectedError: "failed to get HCP caller identity", + }, + "nil payload": { + getCallerIdentityResp: &hcpis.IamServiceGetCallerIdentityOK{ + Payload: nil, }, - }, nil) - - mockVsClient := clustermocks.NewClientService(t) - mockVsClient. - On("Get", mock.Anything, nil). - Return(&hcpvs.GetOK{ - Payload: &hcpvsm.HashicorpCloudVault20201125GetResponse{ - Cluster: &hcpvsm.HashicorpCloudVault20201125Cluster{ - ID: "cluster-1", - DNSNames: &hcpvsm.HashicorpCloudVault20201125ClusterDNSNames{Proxy: "hcp-proxy-cluster-1.addr:8200"}, - State: hcpvsm.NewHashicorpCloudVault20201125ClusterState( - hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING, - ), - Config: &hcpvsm.HashicorpCloudVault20201125ClusterConfig{ - NetworkConfig: &hcpvsm.HashicorpCloudVault20201125NetworkConfig{ - HTTPProxyOption: hcpvsm.NewHashicorpCloudVault20201125HTTPProxyOption(hcpvsm.HashicorpCloudVault20201125HTTPProxyOptionENABLED), - }, - }, + getCallerIdentityErr: nil, + expectedResult: 0, + expectedError: "", + }, + "nil principal": { + getCallerIdentityResp: &hcpis.IamServiceGetCallerIdentityOK{ + Payload: &iam_models.HashicorpCloudIamGetCallerIdentityResponse{ + Principal: nil, }, }, - }, nil) + getCallerIdentityErr: nil, + expectedResult: 0, + expectedError: "", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + ui, cmd := testHCPConnectCommand() + + mockIamClient := iammocks.NewClientService(t) + mockIamClient. + On("IamServiceGetCallerIdentity", mock.Anything, nil). + Return(test.getCallerIdentityResp, test.getCallerIdentityErr) + + cmd.iamClient = mockIamClient - cmd.rmOrgClient = mockRmOrgClient - cmd.rmProjClient = mockRmProjClient - cmd.vsClient = mockVsClient + // we will only call these if the caller identity call succeeds + if test.expectedResult == 0 { + mockRmOrgClient := orgmocks.NewClientService(t) + mockRmOrgClient. + On("OrganizationServiceList", mock.Anything, nil). + Return(&hcprmo.OrganizationServiceListOK{ + Payload: &models.HashicorpCloudResourcemanagerOrganizationListResponse{ + Organizations: []*models.HashicorpCloudResourcemanagerOrganization{ + { + ID: uuid.New().String(), + Name: "mock-organization-1", + State: models.NewHashicorpCloudResourcemanagerOrganizationOrganizationState( + models.HashicorpCloudResourcemanagerOrganizationOrganizationStateACTIVE, + ), + }, + }, + }, + }, nil) - result := cmd.Run([]string{"-cluster-id", "cluster-1"}) - assert.Equal(t, 0, result) + mockRmProjClient := projmocks.NewClientService(t) + mockRmProjClient. + On("ProjectServiceList", mock.Anything, nil). + Return(&hcprmp.ProjectServiceListOK{ + Payload: &models.HashicorpCloudResourcemanagerProjectListResponse{ + Projects: []*models.HashicorpCloudResourcemanagerProject{ + { + ID: uuid.New().String(), + Name: "mock-project-1", + State: models.NewHashicorpCloudResourcemanagerProjectProjectState( + models.HashicorpCloudResourcemanagerProjectProjectStateACTIVE, + ), + }, + }, + }, + }, nil) + + mockVsClient := clustermocks.NewClientService(t) + mockVsClient. + On("Get", mock.Anything, nil). + Return(&hcpvs.GetOK{ + Payload: &hcpvsm.HashicorpCloudVault20201125GetResponse{ + Cluster: &hcpvsm.HashicorpCloudVault20201125Cluster{ + ID: "cluster-1", + DNSNames: &hcpvsm.HashicorpCloudVault20201125ClusterDNSNames{Proxy: "hcp-proxy-cluster-1.addr:8200"}, + State: hcpvsm.NewHashicorpCloudVault20201125ClusterState( + hcpvsm.HashicorpCloudVault20201125ClusterStateRUNNING, + ), + Config: &hcpvsm.HashicorpCloudVault20201125ClusterConfig{ + NetworkConfig: &hcpvsm.HashicorpCloudVault20201125NetworkConfig{ + HTTPProxyOption: hcpvsm.NewHashicorpCloudVault20201125HTTPProxyOption(hcpvsm.HashicorpCloudVault20201125HTTPProxyOptionENABLED), + }, + }, + }, + }, + }, nil) + + cmd.rmOrgClient = mockRmOrgClient + cmd.rmProjClient = mockRmProjClient + cmd.vsClient = mockVsClient + } + + result := cmd.Run([]string{"-cluster-id", "cluster-1"}) + assert.Equal(t, test.expectedResult, result) + + combined := ui.OutputWriter.String() + ui.ErrorWriter.String() + + if test.expectedError != "" { + assert.Contains(t, combined, test.expectedError) + } else { + assert.Contains(t, combined, "Connected to cluster via HCP proxy") + } + }) + } } func Test_getOrganization(t *testing.T) { @@ -223,12 +310,12 @@ func Test_getOrganization(t *testing.T) { }, }, }, - expectedError: errors.New("invalid HCP organization: mock-organization-4"), + expectedError: fmt.Errorf("invalid HCP organization: mock-organization-4"), }, // Test generic expectedError returned "expectedError": { - expectedError: errors.New("error getting organization"), + expectedError: fmt.Errorf("error getting organization"), }, } @@ -248,7 +335,9 @@ func Test_getOrganization(t *testing.T) { On("OrganizationServiceList", mock.Anything, nil). Return(tst.organizationServiceListResponse, tst.expectedError) - orgID, err := cmd.getOrganization(mockRmOrgClient) + cmd.rmOrgClient = mockRmOrgClient + + orgID, err := cmd.getOrganization() if tst.expectedError != nil { assert.Error(t, err) assert.EqualError(t, err, tst.expectedError.Error()) @@ -344,12 +433,12 @@ func Test_getProject(t *testing.T) { }, }, }, - expectedError: errors.New("invalid HCP project: mock-project-4"), + expectedError: fmt.Errorf("invalid HCP project: mock-project-4"), }, // Test generic expectedError returned "expectedError": { - expectedError: errors.New("error getting project"), + expectedError: fmt.Errorf("error getting project"), }, } @@ -369,7 +458,9 @@ func Test_getProject(t *testing.T) { On("ProjectServiceList", mock.Anything, nil). Return(tst.projectServiceListResponse, tst.expectedError) - projID, err := cmd.getProject("", mockRmProjClient) + cmd.rmProjClient = mockRmProjClient + + projID, err := cmd.getProject("") if tst.expectedError != nil { assert.Error(t, tst.expectedError) } else { @@ -517,7 +608,7 @@ func Test_getCluster(t *testing.T) { }, }, }, - expectedError: errors.New("invalid cluster: cluster-4"), + expectedError: fmt.Errorf("invalid cluster: cluster-4"), }, // Test error handling for cluster still being created @@ -550,7 +641,7 @@ func Test_getCluster(t *testing.T) { }, }, }, - expectedError: errors.New("cluster is still being created"), + expectedError: fmt.Errorf("cluster is still being created"), }, // Test error handling for cluster is locked @@ -583,7 +674,7 @@ func Test_getCluster(t *testing.T) { }, }, }, - expectedError: errors.New("cluster is locked"), + expectedError: fmt.Errorf("cluster is locked"), }, // Test error handling for cluster is locked @@ -616,12 +707,12 @@ func Test_getCluster(t *testing.T) { }, }, }, - expectedError: errors.New("cluster is locked"), + expectedError: fmt.Errorf("cluster is locked"), }, // Test generic expectedError returned "expectedError": { - expectedError: errors.New("error getting cluster"), + expectedError: fmt.Errorf("error getting cluster"), }, } @@ -649,7 +740,9 @@ func Test_getCluster(t *testing.T) { Return(tst.listClustersServiceListResponse, tst.expectedError) } - proxyAddr, err := cmd.getCluster("", "", tst.userParamCluster, mockVsClient) + cmd.vsClient = mockVsClient + + proxyAddr, err := cmd.getCluster("", "", tst.userParamCluster) if tst.expectedError != nil { assert.Error(t, tst.expectedError) } else { @@ -803,7 +896,7 @@ func Test_getProxyAddr(t *testing.T) { expectedProxyAddr: "https://hcp-proxy-cluster-1.addr:8200", userParamOrgID: "invalid-org", userParamProjID: "invalid-proj", - expectedError: errors.New("error getting cluster"), + expectedError: fmt.Errorf("error getting cluster"), }, } @@ -841,7 +934,11 @@ func Test_getProxyAddr(t *testing.T) { Return(tst.projectServiceListResponse, nil) } - proxyAddr, err := cmd.getProxyAddr(mockRmOrgClient, mockRmProjClient, mockVsClient) + cmd.rmOrgClient = mockRmOrgClient + cmd.rmProjClient = mockRmProjClient + cmd.vsClient = mockVsClient + + proxyAddr, err := cmd.getProxyAddr() if tst.expectedError != nil { assert.Error(t, tst.expectedError) } else { diff --git a/mocks/iam/ClientService.go b/mocks/iam/ClientService.go new file mode 100644 index 0000000..da434bb --- /dev/null +++ b/mocks/iam/ClientService.go @@ -0,0 +1,430 @@ +// Code generated by mockery v2.34.2. DO NOT EDIT. + +package mocks + +import ( + iam_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/iam_service" + mock "github.com/stretchr/testify/mock" + + runtime "github.com/go-openapi/runtime" +) + +// ClientService is an autogenerated mock type for the ClientService type +type ClientService struct { + mock.Mock +} + +// IamServiceBatchGetPrincipals provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceBatchGetPrincipals(params *iam_service.IamServiceBatchGetPrincipalsParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceBatchGetPrincipalsOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceBatchGetPrincipalsOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceBatchGetPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceBatchGetPrincipalsOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceBatchGetPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceBatchGetPrincipalsOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceBatchGetPrincipalsOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceBatchGetPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceCreateUserPrincipal provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceCreateUserPrincipal(params *iam_service.IamServiceCreateUserPrincipalParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceCreateUserPrincipalOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceCreateUserPrincipalOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceCreateUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceCreateUserPrincipalOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceCreateUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceCreateUserPrincipalOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceCreateUserPrincipalOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceCreateUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceDeleteOrganizationMembership provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceDeleteOrganizationMembership(params *iam_service.IamServiceDeleteOrganizationMembershipParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceDeleteOrganizationMembershipOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceDeleteOrganizationMembershipOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceDeleteOrganizationMembershipParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceDeleteOrganizationMembershipOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceDeleteOrganizationMembershipParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceDeleteOrganizationMembershipOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceDeleteOrganizationMembershipOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceDeleteOrganizationMembershipParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceGetCallerIdentity provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceGetCallerIdentity(params *iam_service.IamServiceGetCallerIdentityParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceGetCallerIdentityOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceGetCallerIdentityOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetCallerIdentityParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceGetCallerIdentityOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetCallerIdentityParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceGetCallerIdentityOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceGetCallerIdentityOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceGetCallerIdentityParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceGetCurrentUserPrincipal provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceGetCurrentUserPrincipal(params *iam_service.IamServiceGetCurrentUserPrincipalParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceGetCurrentUserPrincipalOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceGetCurrentUserPrincipalOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetCurrentUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceGetCurrentUserPrincipalOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetCurrentUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceGetCurrentUserPrincipalOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceGetCurrentUserPrincipalOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceGetCurrentUserPrincipalParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceGetOrganizationAuthMetadata provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceGetOrganizationAuthMetadata(params *iam_service.IamServiceGetOrganizationAuthMetadataParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceGetOrganizationAuthMetadataOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceGetOrganizationAuthMetadataOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetOrganizationAuthMetadataParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceGetOrganizationAuthMetadataOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetOrganizationAuthMetadataParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceGetOrganizationAuthMetadataOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceGetOrganizationAuthMetadataOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceGetOrganizationAuthMetadataParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceGetUserPrincipalByIDInOrganization provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceGetUserPrincipalByIDInOrganization(params *iam_service.IamServiceGetUserPrincipalByIDInOrganizationParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceGetUserPrincipalByIDInOrganizationOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceGetUserPrincipalByIDInOrganizationOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetUserPrincipalByIDInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceGetUserPrincipalByIDInOrganizationOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetUserPrincipalByIDInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceGetUserPrincipalByIDInOrganizationOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceGetUserPrincipalByIDInOrganizationOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceGetUserPrincipalByIDInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceGetUserPrincipalsByIDsInOrganization provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceGetUserPrincipalsByIDsInOrganization(params *iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceGetUserPrincipalsByIDsInOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceListUserPrincipalsByOrganization provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceListUserPrincipalsByOrganization(params *iam_service.IamServiceListUserPrincipalsByOrganizationParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceListUserPrincipalsByOrganizationOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceListUserPrincipalsByOrganizationOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceListUserPrincipalsByOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceListUserPrincipalsByOrganizationOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceListUserPrincipalsByOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceListUserPrincipalsByOrganizationOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceListUserPrincipalsByOrganizationOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceListUserPrincipalsByOrganizationParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServicePing provides a mock function with given fields: params, opts +func (_m *ClientService) IamServicePing(params *iam_service.IamServicePingParams, opts ...iam_service.ClientOption) (*iam_service.IamServicePingOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServicePingOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServicePingParams, ...iam_service.ClientOption) (*iam_service.IamServicePingOK, error)); ok { + return rf(params, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServicePingParams, ...iam_service.ClientOption) *iam_service.IamServicePingOK); ok { + r0 = rf(params, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServicePingOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServicePingParams, ...iam_service.ClientOption) error); ok { + r1 = rf(params, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceSearchPrincipals provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceSearchPrincipals(params *iam_service.IamServiceSearchPrincipalsParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceSearchPrincipalsOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceSearchPrincipalsOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceSearchPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceSearchPrincipalsOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceSearchPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceSearchPrincipalsOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceSearchPrincipalsOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceSearchPrincipalsParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IamServiceUpdateWebConsolePreferences provides a mock function with given fields: params, authInfo, opts +func (_m *ClientService) IamServiceUpdateWebConsolePreferences(params *iam_service.IamServiceUpdateWebConsolePreferencesParams, authInfo runtime.ClientAuthInfoWriter, opts ...iam_service.ClientOption) (*iam_service.IamServiceUpdateWebConsolePreferencesOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params, authInfo) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *iam_service.IamServiceUpdateWebConsolePreferencesOK + var r1 error + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceUpdateWebConsolePreferencesParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) (*iam_service.IamServiceUpdateWebConsolePreferencesOK, error)); ok { + return rf(params, authInfo, opts...) + } + if rf, ok := ret.Get(0).(func(*iam_service.IamServiceUpdateWebConsolePreferencesParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) *iam_service.IamServiceUpdateWebConsolePreferencesOK); ok { + r0 = rf(params, authInfo, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*iam_service.IamServiceUpdateWebConsolePreferencesOK) + } + } + + if rf, ok := ret.Get(1).(func(*iam_service.IamServiceUpdateWebConsolePreferencesParams, runtime.ClientAuthInfoWriter, ...iam_service.ClientOption) error); ok { + r1 = rf(params, authInfo, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SetTransport provides a mock function with given fields: transport +func (_m *ClientService) SetTransport(transport runtime.ClientTransport) { + _m.Called(transport) +} + +// NewClientService creates a new instance of ClientService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewClientService(t interface { + mock.TestingT + Cleanup(func()) +}) *ClientService { + mock := &ClientService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}