Skip to content
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

Allow declaring decorators on nested child resources #12209

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/Bicep.Core.IntegrationTests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,110 @@ public void NonDecoratorFunction_AttachedToDeclaration_CannotBeUsedAsDecorator()
success.Should().BeFalse();
}
}

/// <summary>
/// https://github.com/Azure/bicep/issues/10970
/// </summary>
[TestMethod]
public void DecoratorsOnNestedChildResource_CanBeUsed()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
var dbs = [
'db1'
'db2'
'db3'
]
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'sql-server-name'
location: 'polandcentral'

@batchSize(1)
@description('Sql Databases')
resource sqlDatabase 'databases' = [for db in dbs: {
name: db
location: 'polandcentral'
}]

@description('Primary Sql Database')
resource primaryDb 'databases' = {
name: 'primary'
location: 'polandcentral'
}
}");
using (new AssertionScope())
{
diagnostics.ExcludingLinterDiagnostics().Should().BeEmpty();
template.Should().NotBeNull()
.And.HaveValueAtPath("$.resources[0].copy.mode", "serial")
.And.HaveValueAtPath("$.resources[0].copy.batchSize", 1);
template.Should().NotBeNull()
.And.HaveValueAtPath("$.resources[0].metadata.description", "Sql Databases");
template.Should().NotBeNull()
.And.HaveValueAtPath("$.resources[1].metadata.description", "Primary Sql Database");
}
}

[TestMethod]
public void DecoratorDescriptionInResourceBody_ShouldPromptForDeclaration()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'sql-server-name'
location: 'polandcentral'

@description('Primary Sql Database')
}
");
using (new AssertionScope())
{
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP132", DiagnosticLevel.Error, "Expected a declaration after the decorator."),
});
template.Should().BeNull();
}
}

[TestMethod]
public void DecoratorBatchSizeInResourceBody_ShouldPromptForResourceDeclaration()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'sql-server-name'
location: 'polandcentral'

@batchSize(1)
}
");
using (new AssertionScope())
{
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP153", DiagnosticLevel.Error, "Expected a resource or module declaration after the decorator."),
});
template.Should().BeNull();
}
}

[TestMethod]
public void UnfinishedDecoratorInResourceBody_ShouldPromptForNamespaceOrDecoratorName()
{
var (template, diagnostics, _) = CompilationHelper.Compile(@"
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'sql-server-name'
location: 'polandcentral'

@
}
");
using (new AssertionScope())
{
diagnostics.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP123", DiagnosticLevel.Error, "Expected a namespace or decorator name at this location."),
});
template.Should().BeNull();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5581,6 +5581,91 @@
"command": "editor.action.triggerParameterHints"
}
},
{
"label": "sqlServer1",
"kind": "interface",
"detail": "sqlServer1",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer1",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer1"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer2",
"kind": "interface",
"detail": "sqlServer2",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer2",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer2"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer3",
"kind": "interface",
"detail": "sqlServer3",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer3",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer3"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer4",
"kind": "interface",
"detail": "sqlServer4",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer4",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer4"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer5",
"kind": "interface",
"detail": "sqlServer5",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer5",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer5"
},
"commitCharacters": [
":"
]
},
{
"label": "startedTypingTypeWithQuotes",
"kind": "interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5545,6 +5545,91 @@
"command": "editor.action.triggerParameterHints"
}
},
{
"label": "sqlServer1",
"kind": "interface",
"detail": "sqlServer1",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer1",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer1"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer2",
"kind": "interface",
"detail": "sqlServer2",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer2",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer2"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer3",
"kind": "interface",
"detail": "sqlServer3",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer3",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer3"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer4",
"kind": "interface",
"detail": "sqlServer4",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer4",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer4"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer5",
"kind": "interface",
"detail": "sqlServer5",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer5",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer5"
},
"commitCharacters": [
":"
]
},
{
"label": "startedTypingTypeWithQuotes",
"kind": "interface",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5573,6 +5573,91 @@
"command": "editor.action.triggerParameterHints"
}
},
{
"label": "sqlServer1",
"kind": "interface",
"detail": "sqlServer1",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer1",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer1"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer2",
"kind": "interface",
"detail": "sqlServer2",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer2",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer2"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer3",
"kind": "interface",
"detail": "sqlServer3",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer3",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer3"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer4",
"kind": "interface",
"detail": "sqlServer4",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer4",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer4"
},
"commitCharacters": [
":"
]
},
{
"label": "sqlServer5",
"kind": "interface",
"detail": "sqlServer5",
"deprecated": false,
"preselect": false,
"sortText": "2_sqlServer5",
"insertTextFormat": "plainText",
"insertTextMode": "adjustIndentation",
"textEdit": {
"range": {},
"newText": "sqlServer5"
},
"commitCharacters": [
":"
]
},
{
"label": "startedTypingTypeWithQuotes",
"kind": "interface",
Expand Down
Loading
Loading