-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
267fb26
commit 2a086b9
Showing
11 changed files
with
129 additions
and
5 deletions.
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
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
36 changes: 36 additions & 0 deletions
36
tests/PSRule.Rules.Azure.Tests/Bicep/ScopeTestCases/BicepScopeTests.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,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Linq; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace PSRule.Rules.Azure.Bicep.ScopeTestCases; | ||
|
||
/// <summary> | ||
/// Tests for validating resource scopes and IDs are generated correctly. | ||
/// </summary> | ||
public sealed class BicepScopeTests : TemplateVisitorTestsBase | ||
{ | ||
[Fact] | ||
public void ProcessTemplate_WhenManagementGroupAtTenant_ShouldReturnCompleteProperties() | ||
{ | ||
var resources = ProcessTemplate(GetSourcePath("Bicep/ScopeTestCases/Tests.Bicep.1.json"), null, out _); | ||
|
||
Assert.NotNull(resources); | ||
|
||
var actual = resources.Where(r => r["name"].Value<string>() == "mg-01").FirstOrDefault(); | ||
Assert.Equal("Microsoft.Management/managementGroups", actual["type"].Value<string>()); | ||
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-01", actual["id"].Value<string>()); | ||
Assert.Equal("/", actual["scope"].Value<string>()); | ||
Assert.Equal("mg-01", actual["properties"]["displayName"].Value<string>()); | ||
Assert.Equal("ffffffff-ffff-ffff-ffff-ffffffffffff", actual["properties"]["tenantId"].Value<string>()); | ||
|
||
actual = resources.Where(r => r["name"].Value<string>() == "mg-02").FirstOrDefault(); | ||
Assert.Equal("Microsoft.Management/managementGroups", actual["type"].Value<string>()); | ||
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-02", actual["id"].Value<string>()); | ||
Assert.Equal("/", actual["scope"].Value<string>()); | ||
Assert.Equal("mg-02", actual["properties"]["displayName"].Value<string>()); | ||
Assert.Equal("ffffffff-ffff-ffff-ffff-ffffffffffff", actual["properties"]["tenantId"].Value<string>()); | ||
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-01", actual["properties"]["details"]["parent"]["id"].Value<string>()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/PSRule.Rules.Azure.Tests/Bicep/ScopeTestCases/Tests.Bicep.1.bicep
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,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
targetScope = 'tenant' | ||
|
||
resource mg_2 'Microsoft.Management/managementGroups@2023-04-01' = { | ||
name: 'mg-02' | ||
properties: { | ||
displayName: 'mg-02' | ||
details: { | ||
parent: mg_1 | ||
} | ||
} | ||
} | ||
|
||
resource mg_1 'Microsoft.Management/managementGroups@2023-04-01' = { | ||
name: 'mg-01' | ||
properties: { | ||
displayName: 'mg-01' | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/PSRule.Rules.Azure.Tests/Bicep/ScopeTestCases/Tests.Bicep.1.json
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,35 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"metadata": { | ||
"_generator": { | ||
"name": "bicep", | ||
"version": "0.31.34.60546", | ||
"templateHash": "7600444971325533016" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Management/managementGroups", | ||
"apiVersion": "2023-04-01", | ||
"name": "mg-02", | ||
"properties": { | ||
"displayName": "mg-02", | ||
"details": { | ||
"parent": "[reference(tenantResourceId('Microsoft.Management/managementGroups', 'mg-01'), '2023-04-01', 'full')]" | ||
} | ||
}, | ||
"dependsOn": [ | ||
"[tenantResourceId('Microsoft.Management/managementGroups', 'mg-01')]" | ||
] | ||
}, | ||
{ | ||
"type": "Microsoft.Management/managementGroups", | ||
"apiVersion": "2023-04-01", | ||
"name": "mg-01", | ||
"properties": { | ||
"displayName": "mg-01" | ||
} | ||
} | ||
] | ||
} |
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