Skip to content

Commit 4ed2332

Browse files
committed
try to remove diffs in tests
1 parent 41096d5 commit 4ed2332

2 files changed

Lines changed: 29 additions & 28 deletions

File tree

tools/StepTemplatePacker/tests/ConvertTo-OctopusJson.Tests.ps1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
$ErrorActionPreference = "Stop";
22
Set-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

1217
Describe "ConvertTo-OctopusDeploy" {
@@ -63,8 +68,7 @@ Describe "ConvertTo-OctopusDeploy" {
6368
It "InputObject is a populated array" {
6469
$input = @( $null, 100, "my string" );
6570
$expected = "[`r`n null,`r`n 100,`r`n `"my string`"`r`n]";
66-
Normalize-NewLines (ConvertTo-OctopusJson -InputObject $input) `
67-
| Should Be (Normalize-NewLines $expected);
71+
Assert-JsonEquivalent -ActualJson (ConvertTo-OctopusJson -InputObject $input) -ExpectedJson $expected
6872
}
6973

7074
It "InputObject is an empty PSCustomObject" {
@@ -101,8 +105,7 @@ Describe "ConvertTo-OctopusDeploy" {
101105
}
102106
"@
103107
$expected = $expected.Trim()
104-
Normalize-NewLines (ConvertTo-OctopusJson -InputObject $input) `
105-
| Should Be (Normalize-NewLines $expected);
108+
Assert-JsonEquivalent -ActualJson (ConvertTo-OctopusJson -InputObject $input) -ExpectedJson $expected
106109
}
107110

108111
It "InputObject is an unhandled type" {

tools/StepTemplatePacker/tests/Set-OctopusStepTemplateProperty.Tests.ps1

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
$ErrorActionPreference = "Stop";
22
Set-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

1217
Describe "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

Comments
 (0)