Skip to content

Conversation

@kewalaka
Copy link
Contributor

@kewalaka kewalaka commented Nov 20, 2025

This pull request improves error handling and test coverage for the addPolicyAndRoleAssets method in alzlib.go, ensuring that duplicate policy and policy set definition versions are handled correctly. The changes refactor how errors are accumulated and reported, and add targeted unit tests for duplicate version scenarios.

Error handling improvements:

  • Refactored error accumulation in addPolicyAndRoleAssets to use multierror.Append for both policy definitions and policy set definitions, ensuring errors are wrapped with descriptive context and reported correctly.

Testing enhancements:

  • Added the TestAddPolicyAndRoleAssetsAllowsDuplicateVersions unit test to verify that adding duplicate versions of policy and policy set definitions works as expected, both when overwriting is allowed and disallowed.
  • Introduced helper functions testPolicyDefinition and testPolicySetDefinition to simplify test setup for policy assets.

fixes: Azure/terraform-provider-alz#188
& Azure/terraform-provider-alz#189

@kewalaka kewalaka changed the title fix: make nil report as no error. add test for addPolicyAndRoleAssets to handle duplicate versions fix: make nil report as no error & add test for duplicate version. Nov 20, 2025
@matt-FFFFFF matt-FFFFFF requested a review from Copilot November 20, 2025 08:30
Copy link

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

This pull request fixes error handling in the addPolicyAndRoleAssets method to properly report nil errors, and adds comprehensive test coverage for duplicate policy version scenarios.

Key changes:

  • Refactored error accumulation from direct slice manipulation to use multierror.Append
  • Added test case TestAddPolicyAndRoleAssetsAllowsDuplicateVersions to verify duplicate version handling
  • Introduced helper functions to simplify test policy creation

Reviewed Changes

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

File Description
alzlib.go Refactored error handling in addPolicyAndRoleAssets to properly accumulate and report errors using multierror.Append instead of direct slice manipulation
alzlib_test.go Added test for duplicate version scenarios and helper functions for creating test policy definitions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matt-FFFFFF
Copy link
Member

Thank you for your contribution @kewalaka!

Due to CI/CD limitations with fork PRs and secrets access, I've migrated your changes to #226. All your commits and authorship have been preserved. Please follow the new PR for any updates or requested changes.

The new PR will run all required checks and can be merged once approved.

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.

[Bug] Bump from 0.19 to 0.20 causes format error

2 participants