Skip to content

Commit 958b2dd

Browse files
authored
test: simplify arm integration tests (#312)
* test: simplify arm integration tests * pr-fix: use correct set file command
1 parent 4cff971 commit 958b2dd

8 files changed

Lines changed: 19 additions & 78 deletions

src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.ARM.tests.ps1

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ InModuleScope Arcus.Scripting.ARM {
66
It "Replaces file path with inline file contents" {
77
# Arrange
88
$armTemplateFile = "$PSScriptRoot\Files\arm-template-inline.json"
9+
$originalContents = Get-Content $armTemplateFile
10+
911
try {
1012
# Act
1113
Inject-ArmContent -Path $armTemplateFile
@@ -15,14 +17,14 @@ InModuleScope Arcus.Scripting.ARM {
1517
$actual = Get-Content $armTemplateFile
1618
$actual[7] | Should -Be ' "value": "this is a test value",'
1719
} finally {
18-
$originalFile = "$PSScriptRoot\Files\arm-template-inline-org.json"
19-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
20+
$originalContents | Out-File -FilePath $armTemplateFile
2021
}
2122
}
2223
if ([Environment]::OSVersion.VersionString -like "*Windows*") {
2324
It "Replaces relative file path with file contents as JSON object (windows)" {
2425
# Arrange
2526
$armTemplateFile = "$PSScriptRoot\Files\arm-template-object (windows).json"
27+
$originalContents = Get-Content $armTemplateFile
2628
try {
2729
# Act
2830
Inject-ArmContent -Path $armTemplateFile
@@ -32,17 +34,16 @@ InModuleScope Arcus.Scripting.ARM {
3234
$actual = Get-Content $armTemplateFile
3335
$actual[7] | Should -Be ' "value": "{\r\n \"test\": \"this is a test value\"\r\n}",'
3436
} finally {
35-
$originalFile = "$PSScriptRoot\Files\arm-template-object-org (windows).json"
36-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
37+
$originalContents | Out-File -FilePath $armTemplateFile
3738
}
3839
}
3940
It "Replaces absolute file path with file contents as JSON object (windows)" {
4041
# Arrange
4142
$armTemplateFile = "$PSScriptRoot\Files\arm-template-object-absolutepath (windows).json"
4243
$armTemplateDirectory = Split-Path $armTemplateFile -Parent
43-
$armTemplate = Get-Content -path $armTemplateFile -Raw
44-
$armTemplate = $armTemplate -replace '#{ArmTemplateDirectory}#', $armTemplateDirectory
45-
$armTemplate | Set-Content -Path $armTemplateFile
44+
$originalContents = Get-Content $armTemplateFile
45+
$armTemplate = $originalContents -replace '#{ArmTemplateDirectory}#', $armTemplateDirectory
46+
$armTemplate | Out-File -FilePath $armTemplateFile
4647

4748
try {
4849
# Act
@@ -53,14 +54,14 @@ InModuleScope Arcus.Scripting.ARM {
5354
$actual = Get-Content $armTemplateFile
5455
$actual[7] | Should -Be ' "value": "{\r\n \"test\": \"this is a test value\"\r\n}",'
5556
} finally {
56-
$originalFile = "$PSScriptRoot\Files\arm-template-object-absolutepath-org (windows).json"
57-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
57+
$originalContents | Out-File -FilePath $armTemplateFile
5858
}
5959
}
6060
} else {
6161
It "Replaces relative file path with file contents as JSON object (linux)" {
6262
# Arrange
6363
$armTemplateFile = "$PSScriptRoot\Files\arm-template-object (linux).json"
64+
$originalContents = Get-Content $armTemplateFile
6465
try {
6566
# Act
6667
Inject-ArmContent -Path $armTemplateFile
@@ -70,17 +71,16 @@ InModuleScope Arcus.Scripting.ARM {
7071
$actual = Get-Content $armTemplateFile
7172
$actual[7] | Should -Be ' "value": "{\n \"test\": \"this is a test value\"\n}",'
7273
} finally {
73-
$originalFile = "$PSScriptRoot\Files\arm-template-object-org (linux).json"
74-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
74+
$originalContents | Out-File -FilePath $armTemplateFile
7575
}
7676
}
7777
It "Replaces absolute file path with file contents as JSON object (linux)" {
7878
# Arrange
7979
$armTemplateFile = "$PSScriptRoot\Files\arm-template-object-absolutepath (linux).json"
8080
$armTemplateDirectory = Split-Path $armTemplateFile -Parent
81-
$armTemplate = Get-Content -path $armTemplateFile -Raw
82-
$armTemplate = $armTemplate -replace '#{ArmTemplateDirectory}#', $armTemplateDirectory
83-
$armTemplate | Set-Content -Path $armTemplateFile
81+
$originalContents = Get-Content -Path $armTemplateFile
82+
$armTemplate = $originalContents -replace '#{ArmTemplateDirectory}#', $armTemplateDirectory
83+
$armTemplate | Out-File -FilePath $armTemplateFile
8484

8585
try {
8686
# Act
@@ -91,14 +91,14 @@ InModuleScope Arcus.Scripting.ARM {
9191
$actual = Get-Content $armTemplateFile
9292
$actual[7] | Should -Be ' "value": "{\n \"test\": \"this is a test value\"\n}",'
9393
} finally {
94-
$originalFile = "$PSScriptRoot\Files\arm-template-object-absolutepath-org (linux).json"
95-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
94+
$originalContents | Out-File -FilePath $armTemplateFile
9695
}
9796
}
9897
}
9998
It "Replaces file path with file contents as escaped JSON and replaced special characters" {
10099
# Arrange
101100
$armTemplateFile = "$PSScriptRoot\Files\arm-template-escape.json"
101+
$originalContents = Get-Content $armTemplateFile
102102
try {
103103
# Act
104104
Inject-ArmContent -Path $armTemplateFile
@@ -108,8 +108,7 @@ InModuleScope Arcus.Scripting.ARM {
108108
$actual = Get-Content $armTemplateFile
109109
$actual[7] | Should -Be ' "value": "<Operation value=\"this is a test value\" />",'
110110
} finally {
111-
$originalFile = "$PSScriptRoot\Files\arm-template-escape-org.json"
112-
Get-Content $originalFile | Out-File -FilePath $armTemplateFile
111+
$originalContents | Out-File -FilePath $armTemplateFile
113112
}
114113
}
115114
}

src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@
7070
<Content Include="appsettings.json" />
7171
<Content Include="Blobs\arcus.png" />
7272
<Content Include="Files\arm-template-object %28linux%29.json" />
73-
<Content Include="Files\arm-template-object-org %28linux%29.json" />
73+
<Content Include="Files\arm-template-object-absolutepath %28linux%29.json" />
74+
<Content Include="Files\arm-template-object-absolutepath %28windows%29.json" />
7475
<Content Include="Files\arm-template-object-value %28linux%29.json" />
7576
<Content Include="Files\arm-template-escape-value.xml" />
7677
<Content Include="Files\arm-template-escape.json" />
77-
<Content Include="Files\arm-template-escape-org.json" />
7878
<Content Include="Files\arm-template-object-value %28windows%29.json" />
7979
<Content Include="Files\arm-template-object %28windows%29.json" />
80-
<Content Include="Files\arm-template-object-org %28windows%29.json" />
8180
<Content Include="Files\arm-template-inline.json" />
8281
<Content Include="Files\arm-template-inline-value.json" />
83-
<Content Include="Files\arm-template-inline-org.json" />
8482
<Content Include="Files\IntegrationAccount\Agreements\agreement1.json" />
8583
<Content Include="Files\IntegrationAccount\Agreements\agreement2.json" />
8684
<Content Include="Files\IntegrationAccount\Assemblies\AssemblyThatDoesSomething.dll" />

src/Arcus.Scripting.Tests.Integration/Files/arm-template-escape-org.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Arcus.Scripting.Tests.Integration/Files/arm-template-inline-org.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.

src/Arcus.Scripting.Tests.Integration/Files/arm-template-object-org (linux).json

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Arcus.Scripting.Tests.Integration/Files/arm-template-object-org (windows).json

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)