Skip to content

Commit dfaf63f

Browse files
committed
Test cases + fixed bicep function
1 parent 20c328a commit dfaf63f

13 files changed

+21719
-16
lines changed

src/Resources/ResourceManager/Implementation/CmdletBase/DeploymentStacksCmdletBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ protected string ResolveBicepFile(string TemplateFile)
4949
if (BicepUtility.IsBicepFile(TemplateFile))
5050
{
5151
filePath = BicepUtility.BuildFile(this.ResolvePath(TemplateFile), this.WriteVerbose, this.WriteWarning);
52+
return filePath;
5253
}
53-
return filePath;
54+
else
55+
return TemplateFile;
56+
5457
}
5558

5659
protected Hashtable GetParameterObject(string parameterFile)

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzManagementGroupDeploymentStack.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ protected override void OnProcessRecord()
167167
throw new PSInvalidOperationException(
168168
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
169169
}
170+
filePath = ResolveBicepFile(filePath);
170171
TemplateUri = filePath;
171172
break;
172173
case ParameterFileTemplateSpecParameterSetName:
@@ -180,6 +181,7 @@ protected override void OnProcessRecord()
180181
throw new PSInvalidOperationException(
181182
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
182183
}
184+
filePath = ResolveBicepFile(filePath);
183185
parameters = this.GetParameterObject(TemplateParameterFile);
184186
TemplateUri = filePath;
185187
break;
@@ -190,6 +192,7 @@ protected override void OnProcessRecord()
190192
throw new PSInvalidOperationException(
191193
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
192194
}
195+
filePath = ResolveBicepFile(filePath);
193196
TemplateUri = filePath;
194197
parameters = GetTemplateParameterObject(TemplateParameterObject);
195198
break;

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzResourceGroupDeploymentStack.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected override void OnProcessRecord()
159159
throw new PSInvalidOperationException(
160160
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
161161
}
162-
filePath = ResolveBicepFile(TemplateFile);
162+
filePath = ResolveBicepFile(filePath);
163163
TemplateUri = filePath;
164164
break;
165165
case ParameterFileTemplateSpecParameterSetName:
@@ -173,7 +173,7 @@ protected override void OnProcessRecord()
173173
throw new PSInvalidOperationException(
174174
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
175175
}
176-
filePath = ResolveBicepFile(TemplateFile);
176+
filePath = ResolveBicepFile(filePath);
177177
parameters = this.GetParameterObject(TemplateParameterFile);
178178
TemplateUri = filePath;
179179
break;
@@ -184,7 +184,7 @@ protected override void OnProcessRecord()
184184
throw new PSInvalidOperationException(
185185
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
186186
}
187-
filePath = ResolveBicepFile(TemplateFile);
187+
filePath = ResolveBicepFile(filePath);
188188
TemplateUri = filePath;
189189
parameters = GetTemplateParameterObject(TemplateParameterObject);
190190
break;

src/Resources/ResourceManager/Implementation/DeploymentStacks/NewAzSubscriptionDeploymentStack.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected override void OnProcessRecord()
160160
throw new PSInvalidOperationException(
161161
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
162162
}
163-
filePath = ResolveBicepFile(TemplateFile);
163+
filePath = ResolveBicepFile(filePath);
164164
TemplateUri = filePath;
165165
break;
166166
case ParameterFileTemplateSpecParameterSetName:
@@ -174,7 +174,7 @@ protected override void OnProcessRecord()
174174
throw new PSInvalidOperationException(
175175
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
176176
}
177-
filePath = ResolveBicepFile(TemplateFile);
177+
filePath = ResolveBicepFile(filePath);
178178
parameters = this.GetParameterObject(TemplateParameterFile);
179179
TemplateUri = filePath;
180180
break;
@@ -185,7 +185,7 @@ protected override void OnProcessRecord()
185185
throw new PSInvalidOperationException(
186186
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
187187
}
188-
filePath = ResolveBicepFile(TemplateFile);
188+
filePath = ResolveBicepFile(filePath);
189189
TemplateUri = filePath;
190190
parameters = GetTemplateParameterObject(TemplateParameterObject);
191191
break;

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzManagmentGroupDeploymentStack.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ protected override void OnProcessRecord()
168168
throw new PSInvalidOperationException(
169169
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
170170
}
171+
filePath = ResolveBicepFile(filePath);
171172
TemplateUri = filePath;
172173
break;
173174
case ParameterFileTemplateSpecParameterSetName:
@@ -181,6 +182,7 @@ protected override void OnProcessRecord()
181182
throw new PSInvalidOperationException(
182183
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
183184
}
185+
filePath = ResolveBicepFile(filePath);
184186
parameters = this.GetParameterObject(TemplateParameterFile);
185187
TemplateUri = filePath;
186188
break;
@@ -191,6 +193,7 @@ protected override void OnProcessRecord()
191193
throw new PSInvalidOperationException(
192194
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
193195
}
196+
filePath = ResolveBicepFile(filePath);
194197
TemplateUri = filePath;
195198
parameters = GetTemplateParameterObject(TemplateParameterObject);
196199
break;

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzResourceGroupDeploymentStack.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,23 @@ protected override void OnProcessRecord()
158158
throw new PSInvalidOperationException(
159159
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
160160
}
161-
filePath = ResolveBicepFile(TemplateFile);
161+
filePath = ResolveBicepFile(filePath);
162162
TemplateUri = filePath;
163163
break;
164164
case ParameterFileTemplateSpecParameterSetName:
165165
case ParameterFileTemplateUriParameterSetName:
166166
parameters = this.GetParameterObject(TemplateParameterFile);
167167
break;
168168
case ParameterFileTemplateFileParameterSetName:
169-
string templatePath = this.TryResolvePath(TemplateFile);
170-
if (!File.Exists(templatePath))
169+
filePath = this.TryResolvePath(TemplateFile);
170+
if (!File.Exists(filePath))
171171
{
172172
throw new PSInvalidOperationException(
173173
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
174174
}
175-
filePath = ResolveBicepFile(TemplateFile);
175+
filePath = ResolveBicepFile(filePath);
176176
parameters = this.GetParameterObject(TemplateParameterFile);
177-
TemplateUri = templatePath;
177+
TemplateUri = filePath;
178178
break;
179179
case ParameterObjectTemplateFileParameterSetName:
180180
filePath = this.TryResolvePath(TemplateFile);
@@ -183,7 +183,7 @@ protected override void OnProcessRecord()
183183
throw new PSInvalidOperationException(
184184
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
185185
}
186-
filePath = ResolveBicepFile(TemplateFile);
186+
filePath = ResolveBicepFile(filePath);
187187
TemplateUri = filePath;
188188
parameters = GetTemplateParameterObject(TemplateParameterObject);
189189
break;

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzSubscriptionDeploymentStack.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected override void OnProcessRecord()
161161
throw new PSInvalidOperationException(
162162
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
163163
}
164-
filePath = ResolveBicepFile(TemplateFile);
164+
filePath = ResolveBicepFile(filePath);
165165
TemplateUri = filePath;
166166
break;
167167
case ParameterFileTemplateSpecParameterSetName:
@@ -175,7 +175,7 @@ protected override void OnProcessRecord()
175175
throw new PSInvalidOperationException(
176176
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
177177
}
178-
filePath = ResolveBicepFile(TemplateFile);
178+
filePath = ResolveBicepFile(filePath);
179179
parameters = this.GetParameterObject(TemplateParameterFile);
180180
TemplateUri = filePath;
181181
break;
@@ -186,7 +186,7 @@ protected override void OnProcessRecord()
186186
throw new PSInvalidOperationException(
187187
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
188188
}
189-
filePath = ResolveBicepFile(TemplateFile);
189+
filePath = ResolveBicepFile(filePath);
190190
TemplateUri = filePath;
191191
parameters = GetTemplateParameterObject(TemplateParameterObject);
192192
break;

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,27 @@ public void TestNewSubscriptionDeploymentStack()
6666
TestRunner.RunTestScript("Test-NewSubscriptionDeploymentStack");
6767
}
6868

69+
[Fact()]
70+
[Trait(Category.AcceptanceType, Category.CheckIn)]
71+
public void TestNewAndSetResourceGroupDeploymentStackWithBicep()
72+
{
73+
TestRunner.RunTestScript("Test-NewAndSetResourceGroupDeploymentStackWithBicep");
74+
}
75+
6976
[Fact()]
7077
[Trait(Category.AcceptanceType, Category.CheckIn)]
7178
public void TestNewAndSetResourceGroupDeploymentStackWithTemplateSpec()
7279
{
7380
TestRunner.RunTestScript("Test-NewAndSetResourceGroupDeploymentStackWithTemplateSpec");
7481
}
7582

83+
[Fact()]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void TestNewAndSetSubscriptionDeploymentStackWithBicep()
86+
{
87+
TestRunner.RunTestScript("Test-NewAndSetSubscriptionDeploymentStackWithBicep");
88+
}
89+
7690
[Fact()]
7791
[Trait(Category.AcceptanceType, Category.CheckIn)]
7892
public void TestNewAndSetSubscriptionDeploymentStackWithTemplateSpec()

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,41 @@ function Test-NewResourceGroupDeploymentStack
177177
}
178178
}
179179

180+
<#
181+
.SYNOPSIS
182+
Tests NEW operation on deploymentStacks at the RG scope with bicep file
183+
#>
184+
function Test-NewAndSetResourceGroupDeploymentStackWithBicep
185+
{
186+
# Setup
187+
$rgname = Get-ResourceGroupName
188+
$rname = Get-ResourceName
189+
$rglocation = "West US 2"
190+
191+
try {
192+
# Prepare
193+
New-AzResourceGroup -Name $rgname -Location $rglocation
194+
195+
#Test - NewByNameAndResourceGroupAndBicepTemplateFile
196+
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -TemplateFile sampleDeploymentBicepFile.bicep
197+
198+
#Assert
199+
Assert-AreEqual "succeeded" $deployment.ProvisioningState
200+
201+
# Test - Set-AzResourceGroupDeploymentStacks
202+
$deployment = Set-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -TemplateFile sampleDeploymentBicepFile2.bicep
203+
204+
# Assert
205+
Assert-AreEqual "succeeded" $deployment.ProvisioningState
206+
}
207+
208+
finally
209+
{
210+
# Cleanup
211+
Clean-ResourceGroup $rgname
212+
}
213+
}
214+
180215
<#
181216
.SYNOPSIS
182217
Tests NEW operation on deploymentStacks at the RG scope using template specs.
@@ -874,6 +909,40 @@ function Test-NewSubscriptionDeploymentStack
874909
}
875910
}
876911

912+
<#
913+
.SYNOPSIS
914+
Tests NEW and SET operation on deploymentStacks at the subscription scope using a bicep template
915+
#>
916+
917+
function Test-NewAndSetSubscriptionDeploymentStackWithBicep
918+
{
919+
# Setup
920+
$rname = Get-ResourceName
921+
$rgname = Get-ResourceName
922+
$rglocation = "West US"
923+
924+
try {
925+
# Test - New-AzSubscriptionDeploymentStacks using templateSpecs
926+
$deployment = New-AzSubscriptionDeploymentStack -Name $rname -TemplateFile sampleSubscriptionDeploymentBicepFile.bicep -Location $rglocation
927+
928+
# Assert
929+
Assert-AreEqual "succeeded" $deployment.ProvisioningState
930+
931+
# Test - Set-AzSubscriptionDeploymentStacks using templateSpecs
932+
$deployment = Set-AzSubscriptionDeploymentStack -Name $rname -TemplateFile sampleSubscriptionDeploymentBicepFile.bicep -Location $rglocation
933+
934+
# Assert
935+
assert-AreEqual "succeeded" $deployment.ProvisioningState
936+
937+
}
938+
939+
finally
940+
{
941+
# Cleanup
942+
Clean-DeploymentAtSubscription $rname
943+
}
944+
}
945+
877946
<#
878947
.SYNOPSIS
879948
Tests NEW and SET operation on deploymentStacks at the subscription scope using template specs

0 commit comments

Comments
 (0)