-
Notifications
You must be signed in to change notification settings - Fork 758
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
Parent property implementation #1800
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cc56e22
MVP for parent property
anthony-c-martin 2ad9838
Use name as-is for nested/parent resource property access
anthony-c-martin 8577272
Add some assertions for parent/nested resources & scopes
anthony-c-martin 73aef17
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin e73f3c0
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin 20081f3
Add some scope validations
anthony-c-martin bfac1ae
Inherit scope from oldest ancestor
anthony-c-martin 008dead
Fix dependsOn generation for resource access syntax
anthony-c-martin aba5af0
Update test baselines
b023eb2
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin bcc737b
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin 9b1084c
Make parent writable; fix tests
anthony-c-martin 3b4b760
Add validation for literal resource names
anthony-c-martin a613559
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin 61f16bb
Add loop tests
anthony-c-martin efe088e
Loops implementation
anthony-c-martin c81ad77
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin 54466fd
Add handling & tests for parent property cycles
anthony-c-martin 709a41f
Merge remote-tracking branch 'origin/main' into antmarti/parent_property
anthony-c-martin 016c843
Reword error messages
anthony-c-martin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.Emit; | ||
using Bicep.Core.Semantics; | ||
using Bicep.Core.TypeSystem; | ||
using Bicep.Core.UnitTests; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.Utils; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.IntegrationTests | ||
{ | ||
[TestClass] | ||
public class ParentPropertyResourceTests | ||
{ | ||
[TestMethod] | ||
public void NestedResources_symbols_are_bound() | ||
{ | ||
var program = @" | ||
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = { | ||
location: resourceGroup().location | ||
name: 'myVnet' | ||
properties: { | ||
addressSpace: { | ||
addressPrefixes: [ | ||
'10.0.0.0/20' | ||
] | ||
} | ||
} | ||
} | ||
|
||
resource subnet1 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = { | ||
parent: vnet | ||
name: 'subnet1' | ||
properties: { | ||
addressPrefix: '10.0.0.0/24' | ||
} | ||
} | ||
|
||
resource subnet2 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = { | ||
parent: vnet | ||
name: 'subnet2' | ||
properties: { | ||
addressPrefix: '10.0.1.0/24' | ||
} | ||
} | ||
"; | ||
|
||
var (template, diags, _) = CompilationHelper.Compile(program); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
template!.Should().NotBeNull(); | ||
diags.Should().BeEmpty(); | ||
|
||
template!.SelectToken("$.resources[0].name")!.Should().DeepEqual("myVnet"); | ||
template!.SelectToken("$.resources[1].name")!.Should().DeepEqual("[format('{0}/{1}', 'myVnet', 'subnet1')]"); | ||
template!.SelectToken("$.resources[2].name")!.Should().DeepEqual("[format('{0}/{1}', 'myVnet', 'subnet2')]"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should the message also say what the permissible types would be? (I haven't yet read how this is used.)
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.
Personally I don't think we should list the available child types in the error - the inconsistency is detected via prefix matching (using the type string to check if it's a child), so it feels like it could be inconsistent or potentially misleading to try and detect possible types from the type system.