11$ErrorActionPreference = " Stop" ;
22Set-StrictMode - Version " Latest" ;
33
4- function Normalize-NewLines ([string ] $value ) {
5- if ($null -eq $value ) {
6- return $null ;
7- }
4+ function Assert-JsonEquivalent {
5+ param (
6+ [Parameter (Mandatory = $true )]
7+ [string ] $ActualJson ,
8+ [Parameter (Mandatory = $true )]
9+ [string ] $ExpectedJson
10+ )
811
9- return $value -replace " `r`n " , " `n " ;
12+ $actualValue = ConvertFrom-Json - InputObject $ActualJson | ConvertTo-Json - Depth 10 - Compress
13+ $expectedValue = ConvertFrom-Json - InputObject $ExpectedJson | ConvertTo-Json - Depth 10 - Compress
14+ $actualValue | Should Be $expectedValue
1015}
1116
1217Describe " Set-OctopusStepTemplateProperty" {
@@ -17,8 +22,7 @@ Describe "Set-OctopusStepTemplateProperty" {
1722 - PropertyName " Octopus.Action.Script.Syntax" `
1823 - Value " PowerShell" ;
1924 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
20- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
21- | Should Be (Normalize- NewLines $expected );
25+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
2226 }
2327
2428 It " No properties exist" {
@@ -27,8 +31,7 @@ Describe "Set-OctopusStepTemplateProperty" {
2731 - PropertyName " Octopus.Action.Script.Syntax" `
2832 - Value " PowerShell" ;
2933 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
30- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
31- | Should Be (Normalize- NewLines $expected );
34+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
3235 }
3336
3437 It " Specified property does not exist" {
@@ -37,8 +40,7 @@ Describe "Set-OctopusStepTemplateProperty" {
3740 - PropertyName " Octopus.Action.Script.Syntax" `
3841 - Value " PowerShell" ;
3942 $expected = " {`r`n `" Properties`" : {`r`n `" otherProperty`" : `"`" ,`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
40- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
41- | Should Be (Normalize- NewLines $expected );
43+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
4244 }
4345
4446 It " Property does not exist" {
@@ -47,8 +49,7 @@ Describe "Set-OctopusStepTemplateProperty" {
4749 - PropertyName " Octopus.Action.Script.Syntax" `
4850 - Value " PowerShell" ;
4951 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
50- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
51- | Should Be (Normalize- NewLines $expected );
52+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
5253 }
5354
5455 It " Property exists with a null value" {
@@ -57,8 +58,7 @@ Describe "Set-OctopusStepTemplateProperty" {
5758 - PropertyName " Octopus.Action.Script.Syntax" `
5859 - Value " PowerShell" ;
5960 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
60- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
61- | Should Be (Normalize- NewLines $expected );
61+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
6262 }
6363
6464 It " Property exists with an empty string value" {
@@ -67,8 +67,7 @@ Describe "Set-OctopusStepTemplateProperty" {
6767 - PropertyName " Octopus.Action.Script.Syntax" `
6868 - Value " PowerShell" ;
6969 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
70- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
71- | Should Be (Normalize- NewLines $expected );
70+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
7271 }
7372
7473 It " Property exists with a string value" {
@@ -77,8 +76,7 @@ Describe "Set-OctopusStepTemplateProperty" {
7776 - PropertyName " Octopus.Action.Script.Syntax" `
7877 - Value " PowerShell" ;
7978 $expected = " {`r`n `" Properties`" : {`r`n `" Octopus.Action.Script.Syntax`" : `" PowerShell`"`r`n }`r`n }" ;
80- Normalize- NewLines (ConvertTo-OctopusJson - InputObject $stepJson ) `
81- | Should Be (Normalize- NewLines $expected );
79+ Assert-JsonEquivalent - ActualJson (ConvertTo-OctopusJson - InputObject $stepJson ) - ExpectedJson $expected
8280 }
8381
8482
0 commit comments