Skip to content

test: refactor armResourceGroupValidationPolicy and add unit test cases#5354

Open
mvacula02 wants to merge 1 commit into
Azure:mainfrom
mvacula02:mvacula/aro-26910
Open

test: refactor armResourceGroupValidationPolicy and add unit test cases#5354
mvacula02 wants to merge 1 commit into
Azure:mainfrom
mvacula02:mvacula/aro-26910

Conversation

@mvacula02
Copy link
Copy Markdown
Collaborator

@mvacula02 mvacula02 commented May 21, 2026

ARO-26910

What

Refactor armResourceGroupValidationPolicy to accept an external ARM resource group client.

Add test scenarios:

  • RG doesn't exist → policy returns a synthetic 404 CloudError response with ResourceGroupNotFound

  • Other than 404 error occurs → error is propagated as-is

Why

Be able to mock RG client and test negative scenarios.

Testing

The PR adds 2 unit tests

PR Checklist

  • PR is scoped to a single task (no mixed concerns)
  • Title follows Conventional Commits format
  • Summary explains the "Why" behind the change
  • Linked to relevant ticket/issue
  • Screenshots included (if graph/UI/metrics changes)
  • Self-reviewed the diff
  • CI/CD checks are passing (ignore Tide)
  • Draft PR used for WIP (if applicable)
  • Commit history is clean (rebased/squashed)
  • Tricky code blocks are commented
  • Specific reviewers tagged
  • All comment threads resolved before merge

Copilot AI review requested due to automatic review settings May 21, 2026 09:32
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mvacula02
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR refactors armResourceGroupValidationPolicy to use an injectable resource group client, enabling better unit testing and decoupling policy behavior from Azure SDK client construction.

Changes:

  • Introduced a resourceGroupClient interface and defaultResourceGroupClient implementation.
  • Updated armResourceGroupValidationPolicy to call the injected client instead of constructing an SDK client inline.
  • Expanded tests to cover ResourceGroupNotFound-to-CloudError translation and propagation of other errors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/util/framework/per_invocation_framework.go Wires the policy to a default resource group client using the invocation credentials.
test/util/framework/azure_client_policies.go Adds injectable RG client abstraction and refactors policy to use it.
test/util/framework/azure_client_policies_test.go Adds a fake RG client and new test cases for 404 CloudError and error propagation.

Comment thread test/util/framework/azure_client_policies.go
Comment thread test/util/framework/azure_client_policies.go
Comment on lines +281 to +288
resp, err := pipeline.Do(req)
require.NoError(t, err)
assert.False(t, called, "transport should not have been called")
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))

var cloudErr arm.CloudError
err = json.NewDecoder(resp.Body).Decode(&cloudErr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point btw. Type of resp.Body is io.ReadCloser, so we are expected to call Close() on it when we finis reading. Adding defer resp.Body.Close() is a good idea.

Copy link
Copy Markdown
Collaborator

@mbukatov mbukatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest addressing one copilot comment, but otherwise it looks good.

}

_, err = client.Get(req.Raw().Context(), rgName, nil)
err = p.rgClient.Get(req.Raw().Context(), subID, rgName)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach. This keeps the client initialization per call.

Comment on lines +281 to +288
resp, err := pipeline.Do(req)
require.NoError(t, err)
assert.False(t, called, "transport should not have been called")
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))

var cloudErr arm.CloudError
err = json.NewDecoder(resp.Body).Decode(&cloudErr)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point btw. Type of resp.Body is io.ReadCloser, so we are expected to call Close() on it when we finis reading. Adding defer resp.Body.Close() is a good idea.

Comment thread test/util/framework/azure_client_policies.go
Comment thread test/util/framework/azure_client_policies.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants