Skip to content

Commit

Permalink
Merge pull request #245 from alexwilcox9/AccessPackageResourceRoleSco…
Browse files Browse the repository at this point in the history
…pe_Delete

Add delete function for `AccessPackageResourceRoleScope`
  • Loading branch information
manicminer authored Jul 13, 2023
2 parents 9893247 + 23bfa7f commit 44feddd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion msgraph/accesspackageresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *AccessPackageResourceClient) Get(ctx context.Context, catalogId string,
accessPackageResources := data.AccessPackageResources

if len(accessPackageResources) == 0 {
return nil, status, fmt.Errorf("No accessPackageResource found with catalogId %v and originId %v", catalogId, originId)
return nil, http.StatusNotFound, fmt.Errorf("No accessPackageResource found with catalogId %v and originId %v", catalogId, originId)
}

return &accessPackageResources[0], status, nil
Expand Down
18 changes: 17 additions & 1 deletion msgraph/accesspackageresourcerolescope.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,24 @@ func (c *AccessPackageResourceRoleScopeClient) Get(ctx context.Context, accessPa
}

if accessPackageResourceRoleScope.ID == nil {
return nil, status, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Get(): Could not find accessPackageResourceRoleScope ID")
return nil, http.StatusNotFound, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Get(): Could not find accessPackageResourceRoleScope ID %s", id)
}

return &accessPackageResourceRoleScope, status, nil
}

// Delete removes a AccessPackageResourceRoleScope.
func (c *AccessPackageResourceRoleScopeClient) Delete(ctx context.Context, accessPackageId string, id string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
ValidStatusCodes: []int{http.StatusOK},
Uri: Uri{
Entity: fmt.Sprintf("/identityGovernance/entitlementManagement/accessPackages/%s/accessPackageResourceRoleScopes/%s", accessPackageId, id),
},
})
if err != nil {
return status, fmt.Errorf("AccessPackageResourceRoleScopeClient.BaseClient.Delete(): %v", err)
}

return status, nil
}
12 changes: 11 additions & 1 deletion msgraph/accesspackageresourcerolescope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestAccessPackageResourceRoleScopeClient(t *testing.T) {
testAccessPackageResourceRoleScopeClient_Get(t, c, *accessPackageResourceRoleScope.AccessPackageId, *accessPackageResourceRoleScope.ID)
testAccessPackageResourceRoleScopeResource_Get(t, c, *accessPackageResourceRequest.CatalogId, *accessPackageResourceRequest.AccessPackageResource.OriginId)
testAccessPackageResourceRoleScopeClient_List(t, c, *accessPackageResourceRoleScope.AccessPackageId)
testAccessPackageResourceRoleScopeClient_Delete(t, c, *accessPackageResourceRoleScope.AccessPackageId, *accessPackageResourceRoleScope.ID)

// Force-replacement scenario
testAccessPackageResourceRoleScopeAP_Delete(t, c, *accessPackage.ID)
Expand All @@ -93,7 +94,6 @@ func TestAccessPackageResourceRoleScopeClient(t *testing.T) {
},
})

//testAccessPackageResourceRoleScopeClient_Delete(t, c, *accessPackageResourceRoleScope)
//testAccessPackageResourceRequestClient_Delete(t, c, accessPackageResourceRequest)

// Cleanup
Expand Down Expand Up @@ -147,6 +147,16 @@ func testAccessPackageResourceRoleScopeClient_List(t *testing.T, c *test.Test, a
return
}

func testAccessPackageResourceRoleScopeClient_Delete(t *testing.T, c *test.Test, accessPackageId string, id string) {
status, err := c.AccessPackageResourceRoleScopeClient.Delete(c.Context, accessPackageId, id)
if err != nil {
t.Fatalf("AccessPackageResourceRequestClient.Delete(): %v", err)
}
if status < 200 || status >= 300 {
t.Fatalf("AccessPackageResourceRequestClient.Delete(): invalid status: %d", status)
}
}

// AccessPackageResourceRequest

func testAccessPackageResourceRoleScopeResourceRequest_Create(t *testing.T, c *test.Test, a msgraph.AccessPackageResourceRequest, pollForId bool) (accessPackageResourceRequest *msgraph.AccessPackageResourceRequest) {
Expand Down

0 comments on commit 44feddd

Please sign in to comment.