From 14639de65144c858d3b60d4789eea9e2fc577e32 Mon Sep 17 00:00:00 2001 From: Phil Adams Date: Wed, 9 Dec 2020 09:48:33 -0600 Subject: [PATCH] fix(Enterprise Management): re-gen service with latest API --- .../enterprise_management_v1.go | 33 +++++-- ...terprise_management_v1_integration_test.go | 2 +- .../enterprise_management_v1_test.go | 96 +++++++++++++++++-- 3 files changed, 115 insertions(+), 16 deletions(-) diff --git a/enterprisemanagementv1/enterprise_management_v1.go b/enterprisemanagementv1/enterprise_management_v1.go index d97749e2..3cbd6a99 100644 --- a/enterprisemanagementv1/enterprise_management_v1.go +++ b/enterprisemanagementv1/enterprise_management_v1.go @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-8d569e8f-20201030-111043 + * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-629bbb97-20201207-171303 */ @@ -110,6 +110,21 @@ func NewEnterpriseManagementV1(options *EnterpriseManagementV1Options) (service return } +// GetServiceURLForRegion returns the service URL to be used for the specified region +func GetServiceURLForRegion(region string) (string, error) { + return "", fmt.Errorf("service does not support regional URLs") +} + +// Clone makes a copy of "enterpriseManagement" suitable for processing requests. +func (enterpriseManagement *EnterpriseManagementV1) Clone() *EnterpriseManagementV1 { + if core.IsNil(enterpriseManagement) { + return nil + } + clone := *enterpriseManagement + clone.Service = enterpriseManagement.Service.Clone() + return &clone +} + // SetServiceURL sets the service URL func (enterpriseManagement *EnterpriseManagementV1) SetServiceURL(url string) error { return enterpriseManagement.Service.SetServiceURL(url) @@ -482,8 +497,8 @@ func (enterpriseManagement *EnterpriseManagementV1) ImportAccountToEnterpriseWit // CreateAccount : Create a new account in an enterprise // Create a new account as a part of an existing enterprise. The API creates an account entity under the parent that is // specified in the payload of the request. The request also takes in the name and the owner of this new account. The -// owner must have a valid IBMid that's registered with {{site.data.keyword.cloud_notm}}, but they don't need to be a -// user in the enterprise account. +// owner must have a valid IBMid that's registered with IBM Cloud, but they don't need to be a user in the enterprise +// account. func (enterpriseManagement *EnterpriseManagementV1) CreateAccount(createAccountOptions *CreateAccountOptions) (result *CreateAccountResponse, response *core.DetailedResponse, err error) { return enterpriseManagement.CreateAccountWithContext(context.Background(), createAccountOptions) } @@ -1021,7 +1036,7 @@ type Account struct { ID *string `json:"id,omitempty"` // The Cloud Resource Name (CRN) of the account. - Crn *string `json:"crn,omitempty"` + CRN *string `json:"crn,omitempty"` // The CRN of the parent of the account. Parent *string `json:"parent,omitempty"` @@ -1078,7 +1093,7 @@ func UnmarshalAccount(m map[string]json.RawMessage, result interface{}) (err err if err != nil { return } - err = core.UnmarshalPrimitive(m, "crn", &obj.Crn) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) if err != nil { return } @@ -1151,7 +1166,7 @@ type AccountGroup struct { ID *string `json:"id,omitempty"` // The Cloud Resource Name (CRN) of the account group. - Crn *string `json:"crn,omitempty"` + CRN *string `json:"crn,omitempty"` // The CRN of the parent of the account group. Parent *string `json:"parent,omitempty"` @@ -1202,7 +1217,7 @@ func UnmarshalAccountGroup(m map[string]json.RawMessage, result interface{}) (er if err != nil { return } - err = core.UnmarshalPrimitive(m, "crn", &obj.Crn) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) if err != nil { return } @@ -1487,7 +1502,7 @@ type Enterprise struct { EnterpriseAccountID *string `json:"enterprise_account_id,omitempty"` // The Cloud Resource Name (CRN) of the enterprise. - Crn *string `json:"crn,omitempty"` + CRN *string `json:"crn,omitempty"` // The name of the enterprise. Name *string `json:"name,omitempty"` @@ -1533,7 +1548,7 @@ func UnmarshalEnterprise(m map[string]json.RawMessage, result interface{}) (err if err != nil { return } - err = core.UnmarshalPrimitive(m, "crn", &obj.Crn) + err = core.UnmarshalPrimitive(m, "crn", &obj.CRN) if err != nil { return } diff --git a/enterprisemanagementv1/enterprise_management_v1_integration_test.go b/enterprisemanagementv1/enterprise_management_v1_integration_test.go index 356abf5c..6730355c 100644 --- a/enterprisemanagementv1/enterprise_management_v1_integration_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_integration_test.go @@ -494,7 +494,7 @@ var _ = Describe("Enterprise Management - Integration Tests", func() { Expect(err).To(BeNil()) Expect(detailedResponse.StatusCode).To(Equal(200)) - crn = *result.Crn + crn = *result.CRN }) It("Successfully Update Account group", func() { diff --git a/enterprisemanagementv1/enterprise_management_v1_test.go b/enterprisemanagementv1/enterprise_management_v1_test.go index de5bb03c..9958764b 100644 --- a/enterprisemanagementv1/enterprise_management_v1_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_test.go @@ -77,6 +77,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(enterpriseManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url from constructor successfully`, func() { SetTestEnvironment(testEnvironment) @@ -87,6 +93,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) @@ -98,6 +110,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) }) Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { @@ -135,6 +153,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) + Describe(`Regional endpoint tests`, func() { + It(`GetServiceURLForRegion(region string)`, func() { + var url string + var err error + url, err = enterprisemanagementv1.GetServiceURLForRegion("INVALID_REGION") + Expect(url).To(BeEmpty()) + Expect(err).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) + }) + }) Describe(`CreateAccountGroup(createAccountGroupOptions *CreateAccountGroupOptions) - Operation response error`, func() { createAccountGroupPath := "/account-groups" Context(`Using mock server endpoint`, func() { @@ -393,7 +421,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "crn": "Crn", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) + fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "crn": "CRN", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) })) }) It(`Invoke ListAccountGroups successfully`, func() { @@ -544,7 +572,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "crn": "Crn", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) + fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "crn": "CRN", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) })) }) It(`Invoke GetAccountGroup successfully`, func() { @@ -769,6 +797,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(enterpriseManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url from constructor successfully`, func() { SetTestEnvironment(testEnvironment) @@ -779,6 +813,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) @@ -790,6 +830,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) }) Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { @@ -827,6 +873,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) + Describe(`Regional endpoint tests`, func() { + It(`GetServiceURLForRegion(region string)`, func() { + var url string + var err error + url, err = enterprisemanagementv1.GetServiceURLForRegion("INVALID_REGION") + Expect(url).To(BeEmpty()) + Expect(err).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) + }) + }) Describe(`ImportAccountToEnterprise(importAccountToEnterpriseOptions *ImportAccountToEnterpriseOptions)`, func() { importAccountToEnterprisePath := "/enterprises/testString/import/accounts/testString" @@ -1183,7 +1239,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "crn": "Crn", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "owner_iam_id": "OwnerIamID", "paid": true, "owner_email": "OwnerEmail", "is_enterprise_account": false, "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) + fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "crn": "CRN", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "owner_iam_id": "OwnerIamID", "paid": true, "owner_email": "OwnerEmail", "is_enterprise_account": false, "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) })) }) It(`Invoke ListAccounts successfully`, func() { @@ -1334,7 +1390,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "crn": "Crn", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "owner_iam_id": "OwnerIamID", "paid": true, "owner_email": "OwnerEmail", "is_enterprise_account": false, "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) + fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "crn": "CRN", "parent": "Parent", "enterprise_account_id": "EnterpriseAccountID", "enterprise_id": "EnterpriseID", "enterprise_path": "EnterprisePath", "name": "Name", "state": "State", "owner_iam_id": "OwnerIamID", "paid": true, "owner_email": "OwnerEmail", "is_enterprise_account": false, "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) })) }) It(`Invoke GetAccount successfully`, func() { @@ -1557,6 +1613,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(enterpriseManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url from constructor successfully`, func() { SetTestEnvironment(testEnvironment) @@ -1567,6 +1629,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) @@ -1578,6 +1646,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) ClearTestEnvironment(testEnvironment) + + clone := enterpriseManagementService.Clone() + Expect(clone).ToNot(BeNil()) + Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) + Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) + Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) }) }) Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { @@ -1615,6 +1689,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) + Describe(`Regional endpoint tests`, func() { + It(`GetServiceURLForRegion(region string)`, func() { + var url string + var err error + url, err = enterprisemanagementv1.GetServiceURLForRegion("INVALID_REGION") + Expect(url).To(BeEmpty()) + Expect(err).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) + }) + }) Describe(`CreateEnterprise(createEnterpriseOptions *CreateEnterpriseOptions) - Operation response error`, func() { createEnterprisePath := "/enterprises" Context(`Using mock server endpoint`, func() { @@ -1876,7 +1960,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "enterprise_account_id": "EnterpriseAccountID", "crn": "Crn", "name": "Name", "domain": "Domain", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) + fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"url": "URL", "id": "ID", "enterprise_account_id": "EnterpriseAccountID", "crn": "CRN", "name": "Name", "domain": "Domain", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}]}`) })) }) It(`Invoke ListEnterprises successfully`, func() { @@ -2027,7 +2111,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "enterprise_account_id": "EnterpriseAccountID", "crn": "Crn", "name": "Name", "domain": "Domain", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) + fmt.Fprintf(res, "%s", `{"url": "URL", "id": "ID", "enterprise_account_id": "EnterpriseAccountID", "crn": "CRN", "name": "Name", "domain": "Domain", "state": "State", "primary_contact_iam_id": "PrimaryContactIamID", "primary_contact_email": "PrimaryContactEmail", "created_at": "2019-01-01T12:00:00", "created_by": "CreatedBy", "updated_at": "2019-01-01T12:00:00", "updated_by": "UpdatedBy"}`) })) }) It(`Invoke GetEnterprise successfully`, func() {