Skip to content

Commit 74f2308

Browse files
Clean up some import-related loose ends (#8858)
* Clean up some import-related loose ends * Add test methods for lambda bug * Rename feature "Imports" -> "Extensibility"
1 parent a523027 commit 74f2308

File tree

33 files changed

+194
-168
lines changed

33 files changed

+194
-168
lines changed

src/Bicep.Core.IntegrationTests/EvaluationTests.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,5 +600,142 @@ param numbers array
600600
evaluated.Should().HaveValueAtPath("$.variables['reduceEmpty']", 0);
601601
}
602602
}
603+
604+
/// <summary>
605+
/// https://github.com/Azure/bicep/issues/8782
606+
/// </summary>
607+
[TestMethod]
608+
public void Issue8782()
609+
{
610+
var result = CompilationHelper.Compile(@"
611+
var testArray = [
612+
{
613+
property1: 'test'
614+
property2: 1
615+
}
616+
{
617+
property1: 'dev'
618+
property2: 2
619+
}
620+
{
621+
property1: 'test'
622+
property2: 0
623+
}
624+
{
625+
property1: 'prod'
626+
property2: 1
627+
}
628+
{
629+
property1: 'prod'
630+
property2: 0
631+
}
632+
{
633+
property1: 'dev'
634+
property2: 0
635+
}
636+
{
637+
property1: 'test'
638+
property2: 0
639+
}
640+
]
641+
642+
output testMap array = map(testArray, record => {
643+
result: record.property2 > 0 ? record.property1 : record.property1 =~ 'test' ? 'test!' : 'notTest!'
644+
})
645+
646+
output testFor array = [for record in testArray: {
647+
result: record.property2 > 0 ? record.property1 : record.property1 =~ 'test' ? 'test!' : 'notTest!'
648+
}]
649+
");
650+
651+
var evaluated = TemplateEvaluator.Evaluate(result.Template);
652+
evaluated.Should().HaveValueAtPath("$.outputs['testMap'].value", JToken.Parse(@"
653+
[
654+
{
655+
""result"": ""test""
656+
},
657+
{
658+
""result"": ""dev""
659+
},
660+
{
661+
""result"": ""test!""
662+
},
663+
{
664+
""result"": ""prod""
665+
},
666+
{
667+
""result"": ""notTest!""
668+
},
669+
{
670+
""result"": ""notTest!""
671+
},
672+
{
673+
""result"": ""test!""
674+
}
675+
]
676+
"));
677+
}
678+
679+
/// <summary>
680+
/// https://github.com/Azure/bicep/issues/8798
681+
/// </summary>
682+
[TestMethod]
683+
public void Issue8798()
684+
{
685+
var result = CompilationHelper.Compile(@"
686+
var dogs = [
687+
{
688+
name: 'Evie'
689+
age: 5
690+
interests: ['Ball', 'Frisbee']
691+
}
692+
{
693+
name: 'Casper'
694+
age: 3
695+
interests: ['Other dogs']
696+
}
697+
{
698+
name: 'Indy'
699+
age: 2
700+
interests: ['Butter']
701+
}
702+
{
703+
name: 'Kira'
704+
age: 8
705+
interests: ['Rubs']
706+
}
707+
]
708+
709+
output iDogs array = filter(dogs, dog => (contains(dog.name, 'C') || contains(dog.name, 'i')))
710+
");
711+
712+
var evaluated = TemplateEvaluator.Evaluate(result.Template);
713+
evaluated.Should().HaveValueAtPath("$.outputs['iDogs'].value", JToken.Parse(@"
714+
[
715+
{
716+
""name"": ""Evie"",
717+
""age"": 5,
718+
""interests"": [
719+
""Ball"",
720+
""Frisbee""
721+
]
722+
},
723+
{
724+
""name"": ""Casper"",
725+
""age"": 3,
726+
""interests"": [
727+
""Other dogs""
728+
]
729+
},
730+
{
731+
""name"": ""Kira"",
732+
""age"": 8,
733+
""interests"": [
734+
""Rubs""
735+
]
736+
}
737+
]
738+
"));
739+
}
603740
}
604741
}

src/Bicep.Core.IntegrationTests/ExamplesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void ExampleIsValid_using_experimental_symbolic_names(EmbeddedFile embedd
9191
[DynamicData(nameof(GetExtensibilityExampleData), DynamicDataSourceType.Method)]
9292
[TestCategory(BaselineHelper.BaselineTestCategory)]
9393
public void ExampleIsValid_extensibility(EmbeddedFile embeddedBicep)
94-
=> RunExampleTest(embeddedBicep, new(ImportsEnabled: true), ".json");
94+
=> RunExampleTest(embeddedBicep, new(ExtensibilityEnabled: true), ".json");
9595

9696
[DataTestMethod]
9797
[DynamicData(nameof(GetAllExampleData), DynamicDataSourceType.Method)]

src/Bicep.Core.IntegrationTests/ExtensibilityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ExtensibilityTests
1919
public TestContext? TestContext { get; set; }
2020

2121
private ServiceBuilder Services => new ServiceBuilder()
22-
.WithFeatureOverrides(new(ImportsEnabled: true))
22+
.WithFeatureOverrides(new(ExtensibilityEnabled: true))
2323
.WithNamespaceProvider(new TestExtensibilityNamespaceProvider(BicepTestConstants.AzResourceTypeLoader));
2424

2525
[TestMethod]

src/Bicep.Core.IntegrationTests/ImportTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Bicep.Core.IntegrationTests
2121
public class ImportTests
2222
{
2323
private ServiceBuilder ServicesWithImports => new ServiceBuilder()
24-
.WithFeatureOverrides(new(TestContext, ImportsEnabled: true));
24+
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true));
2525

2626
private class TestNamespaceProvider : INamespaceProvider
2727
{
@@ -54,7 +54,7 @@ public void Imports_are_disabled_unless_feature_is_enabled()
5454
5555
");
5656
result.Should().HaveDiagnostics(new[] {
57-
("BCP203", DiagnosticLevel.Error, "Import statements are currently not supported."),
57+
("BCP203", DiagnosticLevel.Error, "Using import statements requires enabling EXPERIMENTAL feature \"Extensibility\"."),
5858
});
5959
}
6060

src/Bicep.Core.IntegrationTests/OutputsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class OutputsTests
2222
public TestContext? TestContext { get; set; }
2323

2424
private ServiceBuilder ServicesWithExtensibility => new ServiceBuilder()
25-
.WithFeatureOverrides(new(TestContext, ImportsEnabled: true, ResourceTypedParamsAndOutputsEnabled: true))
25+
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, ResourceTypedParamsAndOutputsEnabled: true))
2626
.WithNamespaceProvider(new TestExtensibilityNamespaceProvider(BicepTestConstants.AzResourceTypeLoader));
2727

2828
[TestMethod]

src/Bicep.Core.IntegrationTests/ParametersTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ParameterTests
2424
public TestContext? TestContext { get; set; }
2525

2626
private ServiceBuilder ServicesWithExtensibility => new ServiceBuilder()
27-
.WithFeatureOverrides(new(TestContext, ImportsEnabled: true, ResourceTypedParamsAndOutputsEnabled: true))
27+
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, ResourceTypedParamsAndOutputsEnabled: true))
2828
.WithNamespaceProvider(new TestExtensibilityNamespaceProvider(BicepTestConstants.AzResourceTypeLoader));
2929

3030
[TestMethod]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"experimentalFeaturesEnabled": {
3-
"imports": true
3+
"extensibility": true
44
}
55
}

src/Bicep.Core.Samples/Files/user_submitted/extensibility/aks/bicepconfig.json

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
# In order to use this functionality, you must first have been enrolled in the extensibility preview.
2-
# You will also need to ensure you've set the BICEP_IMPORTS_ENABLED_EXPERIMENTAL env var to 'true' in both VSCode and your CLI environment.
3-
41
$baseName="majastrzkub"
52
$adminUsername="marcin"
63
$sshRSAPublicKey = Get-Content "~\.ssh\id_rsa.pub";
74

8-
$env:BICEP_IMPORTS_ENABLED_EXPERIMENTAL = 'true'
9-
10-
Select-AzSubscription 996a2f3f-ee01-4ffd-9765-d2c3fc98f30a
11-
12-
# end-to-end deployment
135
New-AzSubscriptionDeployment `
146
-Name $baseName `
157
-Location 'West Central US' `
@@ -19,15 +11,4 @@ New-AzSubscriptionDeployment `
1911
dnsPrefix = $baseName;
2012
linuxAdminUsername = $adminUsername;
2113
sshRSAPublicKey = $sshRSAPublicKey;
22-
}
23-
24-
# deploy kubernetes resources individually
25-
$kubeConfig = ''
26-
27-
New-AzResourceGroupDeployment `
28-
-Name "$baseName-voteapp" `
29-
-TemplateFile '.\modules/kubernetes.bicep' `
30-
-ResourceGroupName $baseName `
31-
-TemplateParameterObject @{
32-
kubeConfig = $kubeConfig
3314
}

src/Bicep.Core.Samples/Files/user_submitted/extensibility/aks/deploy.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/bin/bash
22
# Deploys main.bicep in this folder
33

4-
# Enable Azure CLI & VSCode for extensibility
5-
export BICEP_IMPORTS_ENABLED_EXPERIMENTAL=true
6-
7-
scriptPath=$(dirname "$0")
4+
scriptPath=$(dirname -- "$0")
85
baseName="bicepkubedemo"
96
adminUsername="anthony"
107

0 commit comments

Comments
 (0)