Skip to content

Commit

Permalink
fix(Resource Manager): re-gen service with latest API
Browse files Browse the repository at this point in the history
  • Loading branch information
padamstx committed Dec 11, 2020
1 parent b871759 commit 2de3306
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
29 changes: 22 additions & 7 deletions resourcemanagerv2/resource_manager_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-8d569e8f-20201030-111043
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
*/


Expand Down Expand Up @@ -109,6 +109,21 @@ func NewResourceManagerV2(options *ResourceManagerV2Options) (service *ResourceM
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 "resourceManager" suitable for processing requests.
func (resourceManager *ResourceManagerV2) Clone() *ResourceManagerV2 {
if core.IsNil(resourceManager) {
return nil
}
clone := *resourceManager
clone.Service = resourceManager.Service.Clone()
return &clone
}

// SetServiceURL sets the service URL
func (resourceManager *ResourceManagerV2) SetServiceURL(url string) error {
return resourceManager.Service.SetServiceURL(url)
Expand Down Expand Up @@ -849,7 +864,7 @@ type ResCreateResourceGroup struct {

// The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud Resource
// Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
Crn *string `json:"crn,omitempty"`
CRN *string `json:"crn,omitempty"`
}


Expand All @@ -860,7 +875,7 @@ func UnmarshalResCreateResourceGroup(m map[string]json.RawMessage, result interf
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "crn", &obj.Crn)
err = core.UnmarshalPrimitive(m, "crn", &obj.CRN)
if err != nil {
return
}
Expand All @@ -875,7 +890,7 @@ type ResourceGroup struct {

// The full CRN (cloud resource name) associated with the resource group. For more on this format, see [Cloud Resource
// Names](https://cloud.ibm.com/docs/resources?topic=resources-crn).
Crn *string `json:"crn,omitempty"`
CRN *string `json:"crn,omitempty"`

// An alpha-numeric value identifying the account ID.
AccountID *string `json:"account_id,omitempty"`
Expand Down Expand Up @@ -919,7 +934,7 @@ func UnmarshalResourceGroup(m map[string]json.RawMessage, result interface{}) (e
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "crn", &obj.Crn)
err = core.UnmarshalPrimitive(m, "crn", &obj.CRN)
if err != nil {
return
}
Expand Down Expand Up @@ -999,7 +1014,7 @@ type ResourceQuota struct {

// The full CRN (cloud resource name) associated with the quota. For more on this format, see
// https://cloud.ibm.com/docs/resources?topic=resources-crn#crn.
Crn *string `json:"crn,omitempty"`
CRN *string `json:"crn,omitempty"`

// The limit number of this resource.
Limit *float64 `json:"limit,omitempty"`
Expand All @@ -1017,7 +1032,7 @@ func UnmarshalResourceQuota(m map[string]json.RawMessage, result interface{}) (e
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "crn", &obj.Crn)
err = core.UnmarshalPrimitive(m, "crn", &obj.CRN)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion resourcemanagerv2/resource_manager_v2_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ var _ = Describe("Resource Manager - Integration Tests", func() {
Expect(result.Resources[0]).NotTo(BeNil())
Expect(result.Resources[0].ID).NotTo(BeNil())
Expect(result.Resources[0].Name).NotTo(BeNil())
Expect(result.Resources[0].Crn).NotTo(BeNil())
Expect(result.Resources[0].CRN).NotTo(BeNil())
Expect(result.Resources[0].AccountID).NotTo(BeNil())
Expect(result.Resources[0].QuotaID).NotTo(BeNil())
Expect(result.Resources[0].QuotaURL).NotTo(BeNil())
Expand Down
68 changes: 62 additions & 6 deletions resourcemanagerv2/resource_manager_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(resourceManagerService).ToNot(BeNil())
Expect(serviceErr).To(BeNil())
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
It(`Create service client using external config and set url from constructor successfully`, func() {
SetTestEnvironment(testEnvironment)
Expand All @@ -87,6 +93,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(serviceErr).To(BeNil())
Expect(resourceManagerService.Service.GetServiceURL()).To(Equal("https://testService/api"))
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
It(`Create service client using external config and set url programatically successfully`, func() {
SetTestEnvironment(testEnvironment)
Expand All @@ -98,6 +110,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(serviceErr).To(BeNil())
Expect(resourceManagerService.Service.GetServiceURL()).To(Equal("https://testService/api"))
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
})
Context(`Using external config, construct service client instances with error: Invalid Auth`, func() {
Expand Down Expand Up @@ -135,6 +153,16 @@ var _ = Describe(`ResourceManagerV2`, func() {
})
})
})
Describe(`Regional endpoint tests`, func() {
It(`GetServiceURLForRegion(region string)`, func() {
var url string
var err error
url, err = resourcemanagerv2.GetServiceURLForRegion("INVALID_REGION")
Expect(url).To(BeEmpty())
Expect(err).ToNot(BeNil())
fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error())
})
})
Describe(`ListResourceGroups(listResourceGroupsOptions *ListResourceGroupsOptions) - Operation response error`, func() {
listResourceGroupsPath := "/resource_groups"
Context(`Using mock server endpoint`, func() {
Expand Down Expand Up @@ -209,7 +237,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprintf(res, "%s", `{"resources": [{"id": "ID", "crn": "Crn", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}]}`)
fmt.Fprintf(res, "%s", `{"resources": [{"id": "ID", "crn": "CRN", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}]}`)
}))
})
It(`Invoke ListResourceGroups successfully`, func() {
Expand Down Expand Up @@ -373,7 +401,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(201)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "Crn"}`)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "CRN"}`)
}))
})
It(`Invoke CreateResourceGroup successfully`, func() {
Expand Down Expand Up @@ -520,7 +548,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "Crn", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "CRN", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
}))
})
It(`Invoke GetResourceGroup successfully`, func() {
Expand Down Expand Up @@ -690,7 +718,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "Crn", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "CRN", "account_id": "AccountID", "name": "Name", "state": "State", "default": false, "quota_id": "QuotaID", "quota_url": "QuotaURL", "payment_methods_url": "PaymentMethodsURL", "resource_linkages": [{"anyKey": "anyValue"}], "teams_url": "TeamsURL", "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
}))
})
It(`Invoke UpdateResourceGroup successfully`, func() {
Expand Down Expand Up @@ -899,6 +927,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(resourceManagerService).ToNot(BeNil())
Expect(serviceErr).To(BeNil())
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
It(`Create service client using external config and set url from constructor successfully`, func() {
SetTestEnvironment(testEnvironment)
Expand All @@ -909,6 +943,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(serviceErr).To(BeNil())
Expect(resourceManagerService.Service.GetServiceURL()).To(Equal("https://testService/api"))
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
It(`Create service client using external config and set url programatically successfully`, func() {
SetTestEnvironment(testEnvironment)
Expand All @@ -920,6 +960,12 @@ var _ = Describe(`ResourceManagerV2`, func() {
Expect(serviceErr).To(BeNil())
Expect(resourceManagerService.Service.GetServiceURL()).To(Equal("https://testService/api"))
ClearTestEnvironment(testEnvironment)

clone := resourceManagerService.Clone()
Expect(clone).ToNot(BeNil())
Expect(clone.Service != resourceManagerService.Service).To(BeTrue())
Expect(clone.GetServiceURL()).To(Equal(resourceManagerService.GetServiceURL()))
Expect(clone.Service.Options.Authenticator).To(Equal(resourceManagerService.Service.Options.Authenticator))
})
})
Context(`Using external config, construct service client instances with error: Invalid Auth`, func() {
Expand Down Expand Up @@ -957,6 +1003,16 @@ var _ = Describe(`ResourceManagerV2`, func() {
})
})
})
Describe(`Regional endpoint tests`, func() {
It(`GetServiceURLForRegion(region string)`, func() {
var url string
var err error
url, err = resourcemanagerv2.GetServiceURLForRegion("INVALID_REGION")
Expect(url).To(BeEmpty())
Expect(err).ToNot(BeNil())
fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error())
})
})
Describe(`ListQuotaDefinitions(listQuotaDefinitionsOptions *ListQuotaDefinitionsOptions) - Operation response error`, func() {
listQuotaDefinitionsPath := "/quota_definitions"
Context(`Using mock server endpoint`, func() {
Expand Down Expand Up @@ -1021,7 +1077,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprintf(res, "%s", `{"resources": [{"id": "ID", "name": "Name", "type": "Type", "number_of_apps": 12, "number_of_service_instances": 24, "default_number_of_instances_per_lite_plan": 35, "instances_per_app": 15, "instance_memory": "InstanceMemory", "total_app_memory": "TotalAppMemory", "vsi_limit": 8, "resource_quotas": [{"_id": "ID", "resource_id": "ResourceID", "crn": "Crn", "limit": 5}], "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}]}`)
fmt.Fprintf(res, "%s", `{"resources": [{"id": "ID", "name": "Name", "type": "Type", "number_of_apps": 12, "number_of_service_instances": 24, "default_number_of_instances_per_lite_plan": 35, "instances_per_app": 15, "instance_memory": "InstanceMemory", "total_app_memory": "TotalAppMemory", "vsi_limit": 8, "resource_quotas": [{"_id": "ID", "resource_id": "ResourceID", "crn": "CRN", "limit": 5}], "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}]}`)
}))
})
It(`Invoke ListQuotaDefinitions successfully`, func() {
Expand Down Expand Up @@ -1164,7 +1220,7 @@ var _ = Describe(`ResourceManagerV2`, func() {
// Set mock response
res.Header().Set("Content-type", "application/json")
res.WriteHeader(200)
fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "type": "Type", "number_of_apps": 12, "number_of_service_instances": 24, "default_number_of_instances_per_lite_plan": 35, "instances_per_app": 15, "instance_memory": "InstanceMemory", "total_app_memory": "TotalAppMemory", "vsi_limit": 8, "resource_quotas": [{"_id": "ID", "resource_id": "ResourceID", "crn": "Crn", "limit": 5}], "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
fmt.Fprintf(res, "%s", `{"id": "ID", "name": "Name", "type": "Type", "number_of_apps": 12, "number_of_service_instances": 24, "default_number_of_instances_per_lite_plan": 35, "instances_per_app": 15, "instance_memory": "InstanceMemory", "total_app_memory": "TotalAppMemory", "vsi_limit": 8, "resource_quotas": [{"_id": "ID", "resource_id": "ResourceID", "crn": "CRN", "limit": 5}], "created_at": "2019-01-01T12:00:00", "updated_at": "2019-01-01T12:00:00"}`)
}))
})
It(`Invoke GetQuotaDefinition successfully`, func() {
Expand Down

0 comments on commit 2de3306

Please sign in to comment.