forked from OctopusDeploy/Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTo-OctopusJson.Tests.ps1
More file actions
104 lines (91 loc) · 3.04 KB
/
ConvertTo-OctopusJson.Tests.ps1
File metadata and controls
104 lines (91 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
$ErrorActionPreference = "Stop";
Set-StrictMode -Version "Latest";
. (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) "Test-JsonAssertions.ps1")
Describe "ConvertTo-OctopusDeploy" {
It "InputObject is null" {
$input = $null;
$expected = "null";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is an empty string" {
$input = [string]::Empty;
$expected = "`"`"";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a simple string" {
$input = "my simple string";
$expected = "`"my simple string`"";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a string with special characters" {
$input = "my \ `"string`" with `r`n special `t characters";
$expected = "`"my \\ \`"string\`" with \r\n special \t characters`"";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a positive integer" {
$input = 100;
$expected = "100";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a negative integer" {
$input = -100;
$expected = "-100";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is an empty array" {
$input = @();
$expected = "[]";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a populated array" {
$input = @( $null, 100, "my string" );
$expected = "[`r`n null,`r`n 100,`r`n `"my string`"`r`n]";
ConvertTo-OctopusJson -InputObject $input | Should BeJsonEquivalent $expected
}
It "InputObject is an empty PSCustomObject" {
$input = new-object PSCustomObject;
$expected = "{}";
ConvertTo-OctopusJson -InputObject $input `
| Should Be $expected;
}
It "InputObject is a populated PSCustomObject" {
$input = [PSCustomObject] [ordered] @{
"myNull" = $null
"myInt" = 100
"myString" = "text"
"myArray" = @( $null, 200, "string", [PSCustomObject] [ordered] @{ "nestedProperty" = "nestedValue" } )
"myPsObject" = [PSCustomObject] [ordered] @{ "childProperty" = "childValue" }
};
$expected = @"
{
"myNull": null,
"myInt": 100,
"myString": "text",
"myArray": [
null,
200,
"string",
{
"nestedProperty": "nestedValue"
}
],
"myPsObject": {
"childProperty": "childValue"
}
}
"@
$expected = $expected.Trim()
ConvertTo-OctopusJson -InputObject $input | Should BeJsonEquivalent $expected
}
It "InputObject is an unhandled type" {
{ ConvertTo-OctopusJson -InputObject ([System.Guid]::NewGuid()) } `
| Should Throw "Unhandled input object type 'System.Guid'.";
}
}