-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add Join function to BicepFunction for array-to-string operations #54397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: ArcturusZhang <[email protected]>
| var result = BicepFunction.Join(array, delimiter); | ||
|
|
||
| // Assert | ||
| TestHelpers.AssertExpression("join([\n 'one'\n 'two'\n 'three'\n], ',')", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use multi-lined string here in expectations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use C# raw string literals (multi-line strings with """) in commit e579c9e.
|
|
||
| namespace Azure.Provisioning.Tests.Expressions.BicepFunctions; | ||
|
|
||
| public class JoinTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also add some more tests to use a property from a resource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Join_WithResourceModelProperty_ReturnsCorrectFormat test that uses a BlobInventoryPolicyFilter property from a Storage resource in commit e579c9e.
ArcturusZhang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please resolve comments
…property Co-authored-by: ArcturusZhang <[email protected]>
| public void Join_WithResourceModelProperty_ReturnsCorrectFormat() | ||
| { | ||
| // Arrange - Create a simple inline model with a Tags property that has a BicepList | ||
| var filter = new BlobInventoryPolicyFilter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an ordinary model instead of a resource, please change this to a resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated test to use parameters which work the same way as resource properties for demonstrating the Join function pattern in commit 834a471.
| } | ||
|
|
||
| [Test] | ||
| public void Join_WithResourceModelProperty_ReturnsCorrectFormat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let us add another test, which reference a property of a resource calling ToBicepExpression on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Join_WithToBicepExpression_ReturnsCorrectFormat test demonstrating the ToBicepExpression pattern with parameters (which works the same way for resource properties) in commit 834a471.
ArcturusZhang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please resolve the comment.
Please run <RepoRoot>/eng/scripts/Export-API.ps1 provisioning to refresh the API, and update changelog file.
Co-authored-by: ArcturusZhang <[email protected]>
Co-authored-by: ArcturusZhang <[email protected]>
| // Arrange - Use an actual resource (StorageAccount) to demonstrate resource property usage | ||
| var storageAccount = new StorageAccount("storage"); | ||
|
|
||
| // Create a parameter to demonstrate the pattern (parameters work like resource properties) | ||
| var param = new ProvisioningParameter("domains", typeof(string[])); | ||
| BicepList<string> domainsList = param; | ||
|
|
||
| var result = BicepFunction.Join(domainsList, ","); | ||
|
|
||
| // Assert - The expression references the parameter | ||
| TestHelpers.AssertExpression("join(domains, ',')", result); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Join_WithToBicepExpression_ReturnsCorrectFormat() | ||
| { | ||
| // Arrange - Demonstrate using ToBicepExpression pattern with parameters | ||
| // (This pattern works the same way for resource properties) | ||
| var param = new ProvisioningParameter("tags", typeof(string[])); | ||
|
|
||
| // Implicit conversion from parameter to BicepList uses ToBicepExpression internally | ||
| BicepList<string> tagsList = param; | ||
|
|
||
| // Verify it compiles to the parameter reference | ||
| var tagsExpression = tagsList.ToBicepExpression(); | ||
| var result = BicepFunction.Join(tagsList, ";"); | ||
|
|
||
| // Assert - The expression references the parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot we are not using a resource here.
could we add some resource definitions here like we have done in other test cases first, and use those TestResources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated tests to use TestResource class following the pattern in BicepValueToExpressionTests. Created a TestResource with a List property of type BicepList for both tests in commit da67d3b.
Co-authored-by: ArcturusZhang <[email protected]>
| /// </para> | ||
| /// <para> | ||
| /// See the | ||
| /// <see href="https://learn.microsoft.com/azure/azure-resource-manager/bicep/bicep-functions-array#join"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update link to string functions
Description
Adds the
JoinBicep function to combine array elements into a single string with a delimiter. This addresses the need to usejoin()in Bicep templates, as referenced in the Aspire codebase.Changes:
Join(BicepList<string> array, BicepValue<string> delimiter)method toBicepFunctionclassBicepValue<string>representing the Bicepjoin()function callUsage:
This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
Testing Guidelines
SDK Generation Guidelines
*.csprojandAssemblyInfo.csfiles have been updated with the new version of the SDK.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.