From ff69f2ea00b94cbf331c9b21a24630dd913b0fb7 Mon Sep 17 00:00:00 2001 From: Shaun-Colley Date: Mon, 22 Mar 2021 15:13:48 -0500 Subject: [PATCH 1/2] fix(IAM Policy Management): updated examples and tests for recent changes in API --- .../iam_policy_management_v1.go | 213 ++++++++++--- .../iam_policy_management_v1_examples_test.go | 25 ++ ...m_policy_management_v1_integration_test.go | 26 ++ .../iam_policy_management_v1_test.go | 298 +++++++++++++++--- 4 files changed, 484 insertions(+), 78 deletions(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1.go b/iampolicymanagementv1/iam_policy_management_v1.go index 4e3cf23d..9a61804f 100644 --- a/iampolicymanagementv1/iam_policy_management_v1.go +++ b/iampolicymanagementv1/iam_policy_management_v1.go @@ -15,9 +15,8 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-9b90c5f5-20210129-120415 + * IBM OpenAPI SDK Code Generator Version: 3.29.1-b338fb38-20210313-010605 */ - // Package iampolicymanagementv1 : Operations and models for the IamPolicyManagementV1 service package iampolicymanagementv1 @@ -163,9 +162,9 @@ func (iamPolicyManagement *IamPolicyManagementV1) DisableRetries() { // ListPolicies : Get policies by attributes // Get policies and filter by attributes. While managing policies, you may want to retrieve policies in the account and // filter by attribute values. This can be done through query parameters. Currently, only the following attributes are -// supported: account_id, iam_id, access_group_id, type, service_type, sort and format. account_id is a required query -// parameter. Only policies that have the specified attributes and that the caller has read access to are returned. If -// the caller does not have read access to any policies an empty array is returned. +// supported: account_id, iam_id, access_group_id, type, service_type, sort, format and state. account_id is a required +// query parameter. Only policies that have the specified attributes and that the caller has read access to are +// returned. If the caller does not have read access to any policies an empty array is returned. func (iamPolicyManagement *IamPolicyManagementV1) ListPolicies(listPoliciesOptions *ListPoliciesOptions) (result *PolicyList, response *core.DetailedResponse, err error) { return iamPolicyManagement.ListPoliciesWithContext(context.Background(), listPoliciesOptions) } @@ -227,6 +226,9 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPoliciesWithContext(ctx co if listPoliciesOptions.Format != nil { builder.AddQuery("format", fmt.Sprint(*listPoliciesOptions.Format)) } + if listPoliciesOptions.State != nil { + builder.AddQuery("state", fmt.Sprint(*listPoliciesOptions.State)) + } request, err := builder.Build() if err != nil { @@ -252,17 +254,23 @@ func (iamPolicyManagement *IamPolicyManagementV1) ListPoliciesWithContext(ctx co // **authorization**. A policy administrator might want to create an access policy which grants access to a user, // service-id, or an access group. They might also want to create an authorization policy and setup access between // services. -// ### Access To create an access policy, use **`"type": "access"`** in the body. The possible subject attributes are -// **`iam_id`** and **`access_group_id`**. Use the **`iam_id`** subject attribute for assigning access for a user or -// service-id. Use the **`access_group_id`** subject attribute for assigning access for an access group. The roles must -// be a subset of a service's or the platform's supported roles. The resource attributes must be a subset of a service's -// or the platform's supported attributes. The policy resource must include either the **`serviceType`**, -// **`serviceName`**, or **`resourceGroupId`** attribute and the **`accountId`** attribute.` If the subject is a locked -// service-id, the request will fail. -// ### Authorization Authorization policies are supported by services on a case by case basis. Refer to service -// documentation to verify their support of authorization policies. To create an authorization policy, use **`"type": -// "authorization"`** in the body. The subject attributes must match the supported authorization subjects of the -// resource. Multiple subject attributes might be provided. The following attributes are supported: +// +// ### Access +// +// To create an access policy, use **`"type": "access"`** in the body. The possible subject attributes are **`iam_id`** +// and **`access_group_id`**. Use the **`iam_id`** subject attribute for assigning access for a user or service-id. Use +// the **`access_group_id`** subject attribute for assigning access for an access group. The roles must be a subset of a +// service's or the platform's supported roles. The resource attributes must be a subset of a service's or the +// platform's supported attributes. The policy resource must include either the **`serviceType`**, **`serviceName`**, +// or **`resourceGroupId`** attribute and the **`accountId`** attribute.` If the subject is a locked service-id, the +// request will fail. +// +// ### Authorization +// +// Authorization policies are supported by services on a case by case basis. Refer to service documentation to verify +// their support of authorization policies. To create an authorization policy, use **`"type": "authorization"`** in the +// body. The subject attributes must match the supported authorization subjects of the resource. Multiple subject +// attributes might be provided. The following attributes are supported: // serviceName, serviceInstance, region, resourceType, resource, accountId The policy roles must be a subset of the // supported authorization roles supported by the target service. The user must also have the same level of access or // greater to the target resource in order to grant the role. The resource attributes must be a subset of a service's or @@ -348,16 +356,22 @@ func (iamPolicyManagement *IamPolicyManagementV1) CreatePolicyWithContext(ctx co // UpdatePolicy : Update a policy // Update a policy to grant access between a subject and a resource. A policy administrator might want to update an // existing policy. The policy type cannot be changed (You cannot change an access policy to an authorization policy). -// ### Access To update an access policy, use **`"type": "access"`** in the body. The possible subject attributes are -// **`iam_id`** and **`access_group_id`**. Use the **`iam_id`** subject attribute for assigning access for a user or -// service-id. Use the **`access_group_id`** subject attribute for assigning access for an access group. The roles must -// be a subset of a service's or the platform's supported roles. The resource attributes must be a subset of a service's -// or the platform's supported attributes. The policy resource must include either the **`serviceType`**, -// **`serviceName`**, or **`resourceGroupId`** attribute and the **`accountId`** attribute.` If the subject is a locked -// service-id, the request will fail. -// ### Authorization To update an authorization policy, use **`"type": "authorization"`** in the body. The subject -// attributes must match the supported authorization subjects of the resource. Multiple subject attributes might be -// provided. The following attributes are supported: +// +// ### Access +// +// To update an access policy, use **`"type": "access"`** in the body. The possible subject attributes are **`iam_id`** +// and **`access_group_id`**. Use the **`iam_id`** subject attribute for assigning access for a user or service-id. Use +// the **`access_group_id`** subject attribute for assigning access for an access group. The roles must be a subset of a +// service's or the platform's supported roles. The resource attributes must be a subset of a service's or the +// platform's supported attributes. The policy resource must include either the **`serviceType`**, **`serviceName`**, +// or **`resourceGroupId`** attribute and the **`accountId`** attribute.` If the subject is a locked service-id, the +// request will fail. +// +// ### Authorization +// +// To update an authorization policy, use **`"type": "authorization"`** in the body. The subject attributes must match +// the supported authorization subjects of the resource. Multiple subject attributes might be provided. The following +// attributes are supported: // serviceName, serviceInstance, region, resourceType, resource, accountId The policy roles must be a subset of the // supported authorization roles supported by the target service. The user must also have the same level of access or // greater to the target resource in order to grant the role. The resource attributes must be a subset of a service's or @@ -551,6 +565,78 @@ func (iamPolicyManagement *IamPolicyManagementV1) DeletePolicyWithContext(ctx co return } +// PatchPolicy : Restore a deleted policy by ID +// Restore a policy that has recently been deleted. A policy administrator might want to restore a deleted policy. To +// restore a policy, use **`"state": "active"`** in the body. +func (iamPolicyManagement *IamPolicyManagementV1) PatchPolicy(patchPolicyOptions *PatchPolicyOptions) (result *Policy, response *core.DetailedResponse, err error) { + return iamPolicyManagement.PatchPolicyWithContext(context.Background(), patchPolicyOptions) +} + +// PatchPolicyWithContext is an alternate form of the PatchPolicy method which supports a Context parameter +func (iamPolicyManagement *IamPolicyManagementV1) PatchPolicyWithContext(ctx context.Context, patchPolicyOptions *PatchPolicyOptions) (result *Policy, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(patchPolicyOptions, "patchPolicyOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(patchPolicyOptions, "patchPolicyOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "policy_id": *patchPolicyOptions.PolicyID, + } + + builder := core.NewRequestBuilder(core.PATCH) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = iamPolicyManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(iamPolicyManagement.Service.Options.URL, `/v1/policies/{policy_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range patchPolicyOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("iam_policy_management", "V1", "PatchPolicy") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + if patchPolicyOptions.IfMatch != nil { + builder.AddHeader("If-Match", fmt.Sprint(*patchPolicyOptions.IfMatch)) + } + + body := make(map[string]interface{}) + if patchPolicyOptions.State != nil { + body["state"] = patchPolicyOptions.State + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = iamPolicyManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalPolicy) + if err != nil { + return + } + response.Result = result + + return +} + // ListRoles : Get roles by filters // Get roles based on the filters. While managing roles, you may want to retrieve roles and filter by usages. This can // be done through query parameters. Currently, we only support the following attributes: account_id, and service_name. @@ -1189,6 +1275,9 @@ type ListPoliciesOptions struct { // Include additional data per policy returned [include_last_permit, display]. Format *string + // The state of the policy, 'active' or 'deleted'. + State *string + // Allows users to set headers on API requests Headers map[string]string } @@ -1260,6 +1349,12 @@ func (options *ListPoliciesOptions) SetFormat(format string) *ListPoliciesOption return options } +// SetState : Allow user to set State +func (options *ListPoliciesOptions) SetState(state string) *ListPoliciesOptions { + options.State = core.StringPtr(state) + return options +} + // SetHeaders : Allow user to set Headers func (options *ListPoliciesOptions) SetHeaders(param map[string]string) *ListPoliciesOptions { options.Headers = param @@ -1310,6 +1405,54 @@ func (options *ListRolesOptions) SetHeaders(param map[string]string) *ListRolesO return options } +// PatchPolicyOptions : The PatchPolicy options. +type PatchPolicyOptions struct { + // The policy ID. + PolicyID *string `validate:"required,ne="` + + // The revision number for updating a policy and must match the ETag value of the existing policy. The Etag can be + // retrieved using the GET /v1/policies/{policy_id} API and looking at the ETag response header. + IfMatch *string `validate:"required"` + + // The policy state; either 'active' or 'deleted'. + State *string + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewPatchPolicyOptions : Instantiate PatchPolicyOptions +func (*IamPolicyManagementV1) NewPatchPolicyOptions(policyID string, ifMatch string) *PatchPolicyOptions { + return &PatchPolicyOptions{ + PolicyID: core.StringPtr(policyID), + IfMatch: core.StringPtr(ifMatch), + } +} + +// SetPolicyID : Allow user to set PolicyID +func (options *PatchPolicyOptions) SetPolicyID(policyID string) *PatchPolicyOptions { + options.PolicyID = core.StringPtr(policyID) + return options +} + +// SetIfMatch : Allow user to set IfMatch +func (options *PatchPolicyOptions) SetIfMatch(ifMatch string) *PatchPolicyOptions { + options.IfMatch = core.StringPtr(ifMatch) + return options +} + +// SetState : Allow user to set State +func (options *PatchPolicyOptions) SetState(state string) *PatchPolicyOptions { + options.State = core.StringPtr(state) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *PatchPolicyOptions) SetHeaders(param map[string]string) *PatchPolicyOptions { + options.Headers = param + return options +} + // UpdatePolicyOptions : The UpdatePolicy options. type UpdatePolicyOptions struct { // The policy ID. @@ -1506,7 +1649,6 @@ type CustomRole struct { Href *string `json:"href,omitempty"` } - // UnmarshalCustomRole unmarshals an instance of CustomRole from the specified map of raw messages. func UnmarshalCustomRole(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CustomRole) @@ -1600,8 +1742,10 @@ type Policy struct { // The iam ID of the entity that last modified the policy. LastModifiedByID *string `json:"last_modified_by_id,omitempty"` -} + // The policy state; either 'active' or 'deleted'. + State *string `json:"state,omitempty"` +} // UnmarshalPolicy unmarshals an instance of Policy from the specified map of raw messages. func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err error) { @@ -1650,6 +1794,10 @@ func UnmarshalPolicy(m map[string]json.RawMessage, result interface{}) (err erro if err != nil { return } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } @@ -1660,7 +1808,6 @@ type PolicyList struct { Policies []Policy `json:"policies,omitempty"` } - // UnmarshalPolicyList unmarshals an instance of PolicyList from the specified map of raw messages. func UnmarshalPolicyList(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolicyList) @@ -1681,7 +1828,6 @@ type PolicyResource struct { Tags []ResourceTag `json:"tags,omitempty"` } - // UnmarshalPolicyResource unmarshals an instance of PolicyResource from the specified map of raw messages. func UnmarshalPolicyResource(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolicyResource) @@ -1709,7 +1855,6 @@ type PolicyRole struct { Description *string `json:"description,omitempty"` } - // NewPolicyRole : Instantiate PolicyRole (Generic Model Constructor) func (*IamPolicyManagementV1) NewPolicyRole(roleID string) (model *PolicyRole, err error) { model = &PolicyRole{ @@ -1744,7 +1889,6 @@ type PolicySubject struct { Attributes []SubjectAttribute `json:"attributes,omitempty"` } - // UnmarshalPolicySubject unmarshals an instance of PolicySubject from the specified map of raw messages. func UnmarshalPolicySubject(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PolicySubject) @@ -1768,7 +1912,6 @@ type ResourceAttribute struct { Operator *string `json:"operator,omitempty"` } - // NewResourceAttribute : Instantiate ResourceAttribute (Generic Model Constructor) func (*IamPolicyManagementV1) NewResourceAttribute(name string, value string) (model *ResourceAttribute, err error) { model = &ResourceAttribute{ @@ -1810,7 +1953,6 @@ type ResourceTag struct { Operator *string `json:"operator,omitempty"` } - // NewResourceTag : Instantiate ResourceTag (Generic Model Constructor) func (*IamPolicyManagementV1) NewResourceTag(name string, value string) (model *ResourceTag, err error) { model = &ResourceTag{ @@ -1855,7 +1997,6 @@ type Role struct { CRN *string `json:"crn,omitempty"` } - // UnmarshalRole unmarshals an instance of Role from the specified map of raw messages. func UnmarshalRole(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Role) @@ -1891,7 +2032,6 @@ type RoleList struct { SystemRoles []Role `json:"system_roles,omitempty"` } - // UnmarshalRoleList unmarshals an instance of RoleList from the specified map of raw messages. func UnmarshalRoleList(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(RoleList) @@ -1920,7 +2060,6 @@ type SubjectAttribute struct { Value *string `json:"value" validate:"required"` } - // NewSubjectAttribute : Instantiate SubjectAttribute (Generic Model Constructor) func (*IamPolicyManagementV1) NewSubjectAttribute(name string, value string) (model *SubjectAttribute, err error) { model = &SubjectAttribute{ diff --git a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go index e4c44e95..ad5f07b1 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_examples_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_examples_test.go @@ -249,6 +249,31 @@ var _ = Describe(`IamPolicyManagementV1 Examples Tests`, func() { Expect(response.StatusCode).To(Equal(200)) Expect(policy).ToNot(BeNil()) + examplePolicyETag = response.GetHeaders().Get("ETag") + }) + It(`PatchPolicy request example`, func() { + // begin-patch_policy + + options := iamPolicyManagementService.NewPatchPolicyOptions( + examplePolicyID, + examplePolicyETag, + ) + + options.SetState("active") + + policy, response, err := iamPolicyManagementService.PatchPolicy(options) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(policy, "", " ") + fmt.Println(string(b)) + + // end-patch_policy + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(policy).ToNot(BeNil()) + }) It(`ListPolicies request example`, func() { // begin-list_policies diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 3c457514..81cb754b 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -235,6 +235,32 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { Expect(policy.Roles[0].RoleID).To(Equal(options.Roles[0].RoleID)) Expect(policy.Resources).To(Equal(options.Resources)) + testPolicyETag = detailedResponse.GetHeaders().Get(etagHeader) + + }) + }) + + Describe("Patch an access policy", func() { + + It("Successfully patched an access policy", func() { + shouldSkipTest() + Expect(testPolicyId).To(Not(BeNil())) + Expect(testPolicyETag).To(Not(BeNil())) + + // Construct an instance of the PatchPolicyOptions model + options := new(iampolicymanagementv1.PatchPolicyOptions) + options.PolicyID = core.StringPtr(testPolicyId) + options.IfMatch = core.StringPtr(testPolicyETag) + options.State = core.StringPtr("active") + + policy, detailedResponse, err := service.PatchPolicy(options) + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(policy).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "PatchPolicy() result:\n%s\n", common.ToJSON(policy)) + Expect(*policy.ID).To(Equal(testPolicyId)) + Expect(policy.State).To(Equal(options.State)) + }) }) diff --git a/iampolicymanagementv1/iam_policy_management_v1_test.go b/iampolicymanagementv1/iam_policy_management_v1_test.go index 55d29a7f..7d6c302a 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_test.go @@ -176,23 +176,15 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["access_group_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_name"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_value"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["format"]).To(Equal([]string{"testString"})) - + Expect(req.URL.Query()["state"]).To(Equal([]string{"testString"})) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -218,6 +210,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { listPoliciesOptionsModel.TagValue = core.StringPtr("testString") listPoliciesOptionsModel.Sort = core.StringPtr("testString") listPoliciesOptionsModel.Format = core.StringPtr("testString") + listPoliciesOptionsModel.State = core.StringPtr("testString") listPoliciesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Expect response parsing to fail since we are receiving a text/plain response result, response, operationErr := iamPolicyManagementService.ListPolicies(listPoliciesOptionsModel) @@ -252,30 +245,22 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["access_group_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_name"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_value"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["format"]).To(Equal([]string{"testString"})) - + Expect(req.URL.Query()["state"]).To(Equal([]string{"testString"})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}]}`) })) }) It(`Invoke ListPolicies successfully with retries`, func() { @@ -299,6 +284,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { listPoliciesOptionsModel.TagValue = core.StringPtr("testString") listPoliciesOptionsModel.Sort = core.StringPtr("testString") listPoliciesOptionsModel.Format = core.StringPtr("testString") + listPoliciesOptionsModel.State = core.StringPtr("testString") listPoliciesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -338,27 +324,19 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["iam_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["access_group_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_type"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_name"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["tag_value"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["format"]).To(Equal([]string{"testString"})) - + Expect(req.URL.Query()["state"]).To(Equal([]string{"testString"})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}]}`) + fmt.Fprintf(res, "%s", `{"policies": [{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}]}`) })) }) It(`Invoke ListPolicies successfully`, func() { @@ -387,6 +365,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { listPoliciesOptionsModel.TagValue = core.StringPtr("testString") listPoliciesOptionsModel.Sort = core.StringPtr("testString") listPoliciesOptionsModel.Format = core.StringPtr("testString") + listPoliciesOptionsModel.State = core.StringPtr("testString") listPoliciesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -416,6 +395,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { listPoliciesOptionsModel.TagValue = core.StringPtr("testString") listPoliciesOptionsModel.Sort = core.StringPtr("testString") listPoliciesOptionsModel.Format = core.StringPtr("testString") + listPoliciesOptionsModel.State = core.StringPtr("testString") listPoliciesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := iamPolicyManagementService.SetServiceURL("") @@ -556,7 +536,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke CreatePolicy successfully with retries`, func() { @@ -663,7 +643,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke CreatePolicy successfully`, func() { @@ -914,7 +894,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke UpdatePolicy successfully with retries`, func() { @@ -1022,7 +1002,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke UpdatePolicy successfully`, func() { @@ -1219,7 +1199,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke GetPolicy successfully with retries`, func() { @@ -1273,7 +1253,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) })) }) It(`Invoke GetPolicy successfully`, func() { @@ -1404,6 +1384,231 @@ var _ = Describe(`IamPolicyManagementV1`, func() { }) }) }) + Describe(`PatchPolicy(patchPolicyOptions *PatchPolicyOptions) - Operation response error`, func() { + patchPolicyPath := "/v1/policies/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(patchPolicyPath)) + Expect(req.Method).To(Equal("PATCH")) + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke PatchPolicy with error: Operation response processing error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the PatchPolicyOptions model + patchPolicyOptionsModel := new(iampolicymanagementv1.PatchPolicyOptions) + patchPolicyOptionsModel.PolicyID = core.StringPtr("testString") + patchPolicyOptionsModel.IfMatch = core.StringPtr("testString") + patchPolicyOptionsModel.State = core.StringPtr("testString") + patchPolicyOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + iamPolicyManagementService.EnableRetries(0, 0) + result, response, operationErr = iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`PatchPolicy(patchPolicyOptions *PatchPolicyOptions)`, func() { + patchPolicyPath := "/v1/policies/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(patchPolicyPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) + })) + }) + It(`Invoke PatchPolicy successfully with retries`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + iamPolicyManagementService.EnableRetries(0, 0) + + // Construct an instance of the PatchPolicyOptions model + patchPolicyOptionsModel := new(iampolicymanagementv1.PatchPolicyOptions) + patchPolicyOptionsModel.PolicyID = core.StringPtr("testString") + patchPolicyOptionsModel.IfMatch = core.StringPtr("testString") + patchPolicyOptionsModel.State = core.StringPtr("testString") + patchPolicyOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := iamPolicyManagementService.PatchPolicyWithContext(ctx, patchPolicyOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + iamPolicyManagementService.DisableRetries() + result, response, operationErr := iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = iamPolicyManagementService.PatchPolicyWithContext(ctx, patchPolicyOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(patchPolicyPath)) + Expect(req.Method).To(Equal("PATCH")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.Header["If-Match"]).ToNot(BeNil()) + Expect(req.Header["If-Match"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "type": "Type", "description": "Description", "subjects": [{"attributes": [{"name": "Name", "value": "Value"}]}], "roles": [{"role_id": "RoleID", "display_name": "DisplayName", "description": "Description"}], "resources": [{"attributes": [{"name": "Name", "value": "Value", "operator": "Operator"}], "tags": [{"name": "Name", "value": "Value", "operator": "Operator"}]}], "href": "Href", "created_at": "2019-01-01T12:00:00.000Z", "created_by_id": "CreatedByID", "last_modified_at": "2019-01-01T12:00:00.000Z", "last_modified_by_id": "LastModifiedByID", "state": "State"}`) + })) + }) + It(`Invoke PatchPolicy successfully`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := iamPolicyManagementService.PatchPolicy(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the PatchPolicyOptions model + patchPolicyOptionsModel := new(iampolicymanagementv1.PatchPolicyOptions) + patchPolicyOptionsModel.PolicyID = core.StringPtr("testString") + patchPolicyOptionsModel.IfMatch = core.StringPtr("testString") + patchPolicyOptionsModel.State = core.StringPtr("testString") + patchPolicyOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke PatchPolicy with error: Operation validation and request error`, func() { + iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(iamPolicyManagementService).ToNot(BeNil()) + + // Construct an instance of the PatchPolicyOptions model + patchPolicyOptionsModel := new(iampolicymanagementv1.PatchPolicyOptions) + patchPolicyOptionsModel.PolicyID = core.StringPtr("testString") + patchPolicyOptionsModel.IfMatch = core.StringPtr("testString") + patchPolicyOptionsModel.State = core.StringPtr("testString") + patchPolicyOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := iamPolicyManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the PatchPolicyOptions model with no property values + patchPolicyOptionsModelNew := new(iampolicymanagementv1.PatchPolicyOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = iamPolicyManagementService.PatchPolicy(patchPolicyOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`Service constructor tests`, func() { It(`Instantiate service client`, func() { iamPolicyManagementService, serviceErr := iampolicymanagementv1.NewIamPolicyManagementV1(&iampolicymanagementv1.IamPolicyManagementV1Options{ @@ -1545,9 +1750,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_name"]).To(Equal([]string{"testString"})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -1600,9 +1803,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_name"]).To(Equal([]string{"testString"})) - // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) @@ -1665,9 +1866,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(req.Header["Accept-Language"]).ToNot(BeNil()) Expect(req.Header["Accept-Language"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["service_name"]).To(Equal([]string{"testString"})) - // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) @@ -2609,6 +2808,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { listPoliciesOptionsModel.SetTagValue("testString") listPoliciesOptionsModel.SetSort("testString") listPoliciesOptionsModel.SetFormat("testString") + listPoliciesOptionsModel.SetState("testString") listPoliciesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listPoliciesOptionsModel).ToNot(BeNil()) Expect(listPoliciesOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) @@ -2621,6 +2821,7 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(listPoliciesOptionsModel.TagValue).To(Equal(core.StringPtr("testString"))) Expect(listPoliciesOptionsModel.Sort).To(Equal(core.StringPtr("testString"))) Expect(listPoliciesOptionsModel.Format).To(Equal(core.StringPtr("testString"))) + Expect(listPoliciesOptionsModel.State).To(Equal(core.StringPtr("testString"))) Expect(listPoliciesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewListRolesOptions successfully`, func() { @@ -2636,6 +2837,21 @@ var _ = Describe(`IamPolicyManagementV1`, func() { Expect(listRolesOptionsModel.ServiceName).To(Equal(core.StringPtr("testString"))) Expect(listRolesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewPatchPolicyOptions successfully`, func() { + // Construct an instance of the PatchPolicyOptions model + policyID := "testString" + ifMatch := "testString" + patchPolicyOptionsModel := iamPolicyManagementService.NewPatchPolicyOptions(policyID, ifMatch) + patchPolicyOptionsModel.SetPolicyID("testString") + patchPolicyOptionsModel.SetIfMatch("testString") + patchPolicyOptionsModel.SetState("testString") + patchPolicyOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(patchPolicyOptionsModel).ToNot(BeNil()) + Expect(patchPolicyOptionsModel.PolicyID).To(Equal(core.StringPtr("testString"))) + Expect(patchPolicyOptionsModel.IfMatch).To(Equal(core.StringPtr("testString"))) + Expect(patchPolicyOptionsModel.State).To(Equal(core.StringPtr("testString"))) + Expect(patchPolicyOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewUpdatePolicyOptions successfully`, func() { // Construct an instance of the SubjectAttribute model subjectAttributeModel := new(iampolicymanagementv1.SubjectAttribute) From 65ddaa41bc207c078f054e5cda06752ed8ed58d2 Mon Sep 17 00:00:00 2001 From: Shaun Colley <80714407+swcolley@users.noreply.github.com> Date: Thu, 1 Apr 2021 15:19:29 -0500 Subject: [PATCH 2/2] fix(IAM Policy Management):Update options.PolicyID declaration Co-authored-by: Phil Adams --- .../iam_policy_management_v1_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go index 81cb754b..8e549fcf 100644 --- a/iampolicymanagementv1/iam_policy_management_v1_integration_test.go +++ b/iampolicymanagementv1/iam_policy_management_v1_integration_test.go @@ -249,7 +249,7 @@ var _ = Describe("IAM Policy Management - Integration Tests", func() { // Construct an instance of the PatchPolicyOptions model options := new(iampolicymanagementv1.PatchPolicyOptions) - options.PolicyID = core.StringPtr(testPolicyId) + options.PolicyID = &testPolicyId options.IfMatch = core.StringPtr(testPolicyETag) options.State = core.StringPtr("active")