Skip to content

Commit 90e253f

Browse files
authored
Merge fixes from v1.35.2 (Azure#2804)
1 parent 4c63139 commit 90e253f

File tree

7 files changed

+108
-2
lines changed

7 files changed

+108
-2
lines changed

docs/CHANGELOG-v1.md

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ What's changed since v1.35.1:
4242
- Quality updates to documentation by @lukemurraynz.
4343
[#2789](https://github.com/Azure/PSRule.Rules.Azure/pull/2789)
4444

45+
## v1.35.2
46+
47+
What's changed since v1.35.1:
48+
49+
- Bug fixes:
50+
- Fixed regression when handing ambiguous mock array outputs by @BernieWhite.
51+
[#2801](https://github.com/Azure/PSRule.Rules.Azure/issues/2801)
52+
4553
## v1.35.1
4654

4755
What's changed since v1.35.0:

src/PSRule.Rules.Azure/Data/Template/Mocks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public TValue GetValue<TValue>()
215215

216216
public JToken GetValue(TypePrimitive type)
217217
{
218-
return type == TypePrimitive.Array ? this : null;
218+
return type == TypePrimitive.None || type == TypePrimitive.Array ? this : null;
219219
}
220220

221221
public JToken GetValue(object key)

tests/PSRule.Rules.Azure.Tests/PSRule.Rules.Azure.Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@
239239
<None Update="Tests.Bicep.35.json">
240240
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
241241
</None>
242+
<None Update="Tests.Bicep.36.json">
243+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244+
</None>
242245
<None Update="Tests.Bicep.4.json">
243246
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
244247
</None>

tests/PSRule.Rules.Azure.Tests/TemplateVisitorTests.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ public void UnionMockWithArray()
11011101
[Fact]
11021102
public void ProcessTemplate_WhenIndexIntoMock_ShouldReturnMock()
11031103
{
1104-
var resources = ProcessTemplate(GetSourcePath("Tests.Bicep.35.json"), null, out _);
1104+
ProcessTemplate(GetSourcePath("Tests.Bicep.35.json"), null, out _);
11051105
}
11061106

11071107
/// <summary>
@@ -1116,6 +1116,23 @@ public void ProcessTemplate_WhenParameterNullWithDefault_ShouldUseDefault()
11161116
Assert.Equal("Standard_LRS", actual["sku"]["name"].Value<string>());
11171117
}
11181118

1119+
/// <summary>
1120+
/// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2801.
1121+
/// </summary>
1122+
[Fact]
1123+
public void ProcessTemplate_WhenMockArrayOutputAndTypeIsUnknown_ShouldReturnArray()
1124+
{
1125+
ProcessTemplate(GetSourcePath("Tests.Bicep.36.json"), null, out var templateContext);
1126+
1127+
Assert.True(templateContext.RootDeployment.TryOutput("items", out JObject result));
1128+
var items = result["value"][0]["items"].Value<JArray>();
1129+
1130+
Assert.Single(items);
1131+
var actual = items[0].Value<JObject>();
1132+
Assert.Equal("name1", actual["name"].Value<string>());
1133+
Assert.Equal("value1", actual["value"].Value<string>());
1134+
}
1135+
11191136
#region Helper methods
11201137

11211138
private static string GetSourcePath(string fileName)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
// Test case for https://github.com/Azure/PSRule.Rules.Azure/issues/2801.
5+
6+
module child 'Tests.Bicep.36.child.bicep' = {
7+
name: 'child'
8+
}
9+
10+
output items array = [
11+
{
12+
items: child.outputs.items
13+
}
14+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
output items array = concat(
5+
[],
6+
[
7+
{
8+
name: 'name1'
9+
value: 'value1'
10+
}
11+
]
12+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_generator": {
6+
"name": "bicep",
7+
"version": "0.26.54.24096",
8+
"templateHash": "12279334207887669240"
9+
}
10+
},
11+
"resources": [
12+
{
13+
"type": "Microsoft.Resources/deployments",
14+
"apiVersion": "2022-09-01",
15+
"name": "child",
16+
"properties": {
17+
"expressionEvaluationOptions": {
18+
"scope": "inner"
19+
},
20+
"mode": "Incremental",
21+
"template": {
22+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
23+
"contentVersion": "1.0.0.0",
24+
"metadata": {
25+
"_generator": {
26+
"name": "bicep",
27+
"version": "0.26.54.24096",
28+
"templateHash": "14837468981850150943"
29+
}
30+
},
31+
"resources": [],
32+
"outputs": {
33+
"items": {
34+
"type": "array",
35+
"value": "[concat(createArray(), createArray(createObject('name', 'name1', 'value', 'value1')))]"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
],
42+
"outputs": {
43+
"items": {
44+
"type": "array",
45+
"value": [
46+
{
47+
"items": "[reference(resourceId('Microsoft.Resources/deployments', 'child'), '2022-09-01').outputs.items.value]"
48+
}
49+
]
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)