-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add list method call on Azure resource references (#3430)
* Add list method call on Azure resource references * Address PR feedback * Update baselines * Fix tests
- Loading branch information
1 parent
f1a4461
commit 6987e17
Showing
45 changed files
with
128 additions
and
691 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/Bicep.Core.IntegrationTests/Scenarios/ResourceListFunctionTests.cs
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,95 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.Utils; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.IntegrationTests.Scenarios | ||
{ | ||
[TestClass] | ||
public class ResourceListFunctionTests | ||
{ | ||
[TestMethod] | ||
public void List_wildcard_function_on_resource_references() | ||
{ | ||
var result = CompilationHelper.Compile(@" | ||
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'testacc' | ||
location: 'West US' | ||
kind: 'StorageV2' | ||
sku: { | ||
name: 'Standard_LRS' | ||
} | ||
} | ||
output pkStandard string = listKeys(stg.id, stg.apiVersion).keys[0].value | ||
output pkMethod string = stg.listKeys().keys[0].value | ||
output pkMethodVersionOverride string = stg.listKeys('2021-01-01').keys[0].value | ||
output pkMethodPayload string = stg.listKeys(stg.apiVersion, { | ||
key1: 'val1' | ||
}) | ||
"); | ||
|
||
result.Should().NotHaveAnyDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkStandard'].value", "[listKeys(resourceId('Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethod'].value", "[listKeys(resourceId('Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethodVersionOverride'].value", "[listKeys(resourceId('Microsoft.Storage/storageAccounts', 'testacc'), '2021-01-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethodPayload'].value", "[listKeys(resourceId('Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01', createObject('key1', 'val1'))]"); | ||
} | ||
|
||
[TestMethod] | ||
public void List_wildcard_function_on_cross_scope_resource_references() | ||
{ | ||
var result = CompilationHelper.Compile(@" | ||
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = { | ||
scope: resourceGroup('other') | ||
name: 'testacc' | ||
} | ||
output pkStandard string = listKeys(stg.id, stg.apiVersion).keys[0].value | ||
output pkMethod string = stg.listKeys().keys[0].value | ||
output pkMethodVersionOverride string = stg.listKeys('2021-01-01').keys[0].value | ||
output pkMethodPayload string = stg.listKeys(stg.apiVersion, { | ||
key1: 'val1' | ||
}) | ||
"); | ||
|
||
result.Should().NotHaveAnyDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkStandard'].value", "[listKeys(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'other'), 'Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethod'].value", "[listKeys(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'other'), 'Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethodVersionOverride'].value", "[listKeys(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'other'), 'Microsoft.Storage/storageAccounts', 'testacc'), '2021-01-01').keys[0].value]"); | ||
result.Template.Should().HaveValueAtPath("$.outputs['pkMethodPayload'].value", "[listKeys(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'other'), 'Microsoft.Storage/storageAccounts', 'testacc'), '2019-06-01', createObject('key1', 'val1'))]"); | ||
} | ||
|
||
[TestMethod] | ||
public void Only_list_methods_are_permitted() | ||
{ | ||
var result = CompilationHelper.Compile(@" | ||
resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' existing = { | ||
name: 'testacc' | ||
} | ||
var allowed = { | ||
a: stg.list() | ||
b: stg.listA() | ||
c: stg.listTotallyMadeUpMethod() | ||
} | ||
var disallowed = { | ||
a: stg.lis() | ||
b: stg.lsit() | ||
c: stg.totallyMadeUpMethod() | ||
} | ||
"); | ||
result.Should().HaveDiagnostics(new[] { | ||
("no-unused-vars", DiagnosticLevel.Warning, "Variable \"allowed\" is declared but never used."), | ||
("no-unused-vars", DiagnosticLevel.Warning, "Variable \"disallowed\" is declared but never used."), | ||
("BCP109", DiagnosticLevel.Error, "The type \"Microsoft.Storage/storageAccounts\" does not contain function \"lis\"."), | ||
("BCP109", DiagnosticLevel.Error, "The type \"Microsoft.Storage/storageAccounts\" does not contain function \"lsit\"."), | ||
("BCP109", DiagnosticLevel.Error, "The type \"Microsoft.Storage/storageAccounts\" does not contain function \"totallyMadeUpMethod\"."), | ||
}); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.