|
14 | 14 | describe 'formatting ruby hash to powershell hash string' do |
15 | 15 | describe 'when given correct hash' do |
16 | 16 | it 'outputs correct syntax with simple example' do |
17 | | - expected = <<-HERE |
18 | | -@{ |
19 | | -'ensure' = 'present'; |
20 | | -'name' = 'Web-WebServer' |
21 | | -} |
| 17 | + expected = <<~HERE |
| 18 | + @{ |
| 19 | + 'ensure' = 'present'; |
| 20 | + 'name' = 'Web-WebServer' |
| 21 | + } |
22 | 22 | HERE |
23 | 23 | result = formatter.format('ensure' => 'present', |
24 | 24 | 'name' => 'Web-WebServer') |
25 | 25 | expect(result).to eq expected.strip |
26 | 26 | end |
27 | 27 |
|
28 | 28 | it 'outputs correct syntax with single CimInstance for a CimInstance[] type' do |
29 | | - expected = <<-HERE |
30 | | -@{ |
31 | | -'ensure' = 'Present'; |
32 | | -'name' = 'foo'; |
33 | | -'state' = 'Started'; |
34 | | -'physicalpath' = 'c:/inetpub/wwwroot'; |
35 | | -'bindinginfo' = [CimInstance[]]@( |
36 | | -(New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
37 | | -'protocol' = 'HTTP'; |
38 | | -'port' = 80 |
39 | | -}) |
40 | | -) |
41 | | -} |
| 29 | + expected = <<~HERE |
| 30 | + @{ |
| 31 | + 'ensure' = 'Present'; |
| 32 | + 'name' = 'foo'; |
| 33 | + 'state' = 'Started'; |
| 34 | + 'physicalpath' = 'c:/inetpub/wwwroot'; |
| 35 | + 'bindinginfo' = [CimInstance[]]@( |
| 36 | + (New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
| 37 | + 'protocol' = 'HTTP'; |
| 38 | + 'port' = 80 |
| 39 | + }) |
| 40 | + ) |
| 41 | + } |
42 | 42 | HERE |
43 | 43 |
|
44 | 44 | result = formatter.format('ensure' => 'Present', |
|
57 | 57 | end |
58 | 58 |
|
59 | 59 | it 'outputs correct syntax with single CimInstance for a CimInstance type' do |
60 | | - expected = <<-HERE |
61 | | -@{ |
62 | | -'ensure' = 'Present'; |
63 | | -'name' = 'foo'; |
64 | | -'state' = 'Started'; |
65 | | -'physicalpath' = 'c:/inetpub/wwwroot'; |
66 | | -'authenticationinfo' = [CimInstance](New-CimInstance -ClassName 'MSFT_xWebAuthenticationInformation' -ClientOnly -Property @{ |
67 | | -'anonymous' = $true; |
68 | | -'basic' = $false; |
69 | | -'windows' = $true; |
70 | | -'digest' = $false |
71 | | -}) |
72 | | -} |
| 60 | + expected = <<~HERE |
| 61 | + @{ |
| 62 | + 'ensure' = 'Present'; |
| 63 | + 'name' = 'foo'; |
| 64 | + 'state' = 'Started'; |
| 65 | + 'physicalpath' = 'c:/inetpub/wwwroot'; |
| 66 | + 'authenticationinfo' = [CimInstance](New-CimInstance -ClassName 'MSFT_xWebAuthenticationInformation' -ClientOnly -Property @{ |
| 67 | + 'anonymous' = $true; |
| 68 | + 'basic' = $false; |
| 69 | + 'windows' = $true; |
| 70 | + 'digest' = $false |
| 71 | + }) |
| 72 | + } |
73 | 73 | HERE |
74 | 74 |
|
75 | 75 | result = formatter.format('ensure' => 'Present', |
|
90 | 90 | end |
91 | 91 |
|
92 | 92 | it 'outputs correct syntax with array CimInstance' do |
93 | | - expected = <<-HERE |
94 | | -@{ |
95 | | -'ensure' = 'Present'; |
96 | | -'name' = 'foo'; |
97 | | -'state' = 'Started'; |
98 | | -'physicalpath' = 'c:/inetpub/wwwroot'; |
99 | | -'bindinginfo' = [CimInstance[]]@( |
100 | | -(New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
101 | | -'protocol' = 'HTTP'; |
102 | | -'port' = 80 |
103 | | -}), |
104 | | -(New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
105 | | -'protocol' = 'HTTPS'; |
106 | | -'port' = 443; |
107 | | -'certificatethumbprint' = '5438DC0CB31B1C91B8945C7D91B3338F9C08BEFA'; |
108 | | -'certificatestorename' = 'My'; |
109 | | -'ipaddress' = '*' |
110 | | -}) |
111 | | -) |
112 | | -} |
| 93 | + expected = <<~HERE |
| 94 | + @{ |
| 95 | + 'ensure' = 'Present'; |
| 96 | + 'name' = 'foo'; |
| 97 | + 'state' = 'Started'; |
| 98 | + 'physicalpath' = 'c:/inetpub/wwwroot'; |
| 99 | + 'bindinginfo' = [CimInstance[]]@( |
| 100 | + (New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
| 101 | + 'protocol' = 'HTTP'; |
| 102 | + 'port' = 80 |
| 103 | + }), |
| 104 | + (New-CimInstance -ClassName 'MSFT_xWebBindingInformation' -ClientOnly -Property @{ |
| 105 | + 'protocol' = 'HTTPS'; |
| 106 | + 'port' = 443; |
| 107 | + 'certificatethumbprint' = '5438DC0CB31B1C91B8945C7D91B3338F9C08BEFA'; |
| 108 | + 'certificatestorename' = 'My'; |
| 109 | + 'ipaddress' = '*' |
| 110 | + }) |
| 111 | + ) |
| 112 | + } |
113 | 113 | HERE |
114 | 114 |
|
115 | 115 | result = formatter.format('ensure' => 'Present', |
|
137 | 137 | end |
138 | 138 |
|
139 | 139 | it 'outputs correct syntax with a PSCredential' do |
140 | | - expected = <<-HERE |
141 | | -@{ |
142 | | -'username' = 'jane-doe'; |
143 | | -'description' = 'Jane Doe user'; |
144 | | -'ensure' = 'present'; |
145 | | -'password' = ([PSCustomObject]@{ |
146 | | -'user' = 'jane-doe'; |
147 | | -'password' = 'jane-password' |
148 | | -} | new-pscredential); |
149 | | -'passwordneverexpires' = $false; |
150 | | -'disabled' = $true |
151 | | -} |
| 140 | + expected = <<~HERE |
| 141 | + @{ |
| 142 | + 'username' = 'jane-doe'; |
| 143 | + 'description' = 'Jane Doe user'; |
| 144 | + 'ensure' = 'present'; |
| 145 | + 'password' = ([PSCustomObject]@{ |
| 146 | + 'user' = 'jane-doe'; |
| 147 | + 'password' = 'jane-password' |
| 148 | + } | new-pscredential); |
| 149 | + 'passwordneverexpires' = $false; |
| 150 | + 'disabled' = $true |
| 151 | + } |
152 | 152 | HERE |
153 | 153 | result = formatter.format('username' => 'jane-doe', |
154 | 154 | 'description' => 'Jane Doe user', |
|
166 | 166 | end |
167 | 167 |
|
168 | 168 | it 'outputs correct syntax with MSFT_KeyValuePair' do |
169 | | - expected = <<-HERE |
170 | | -@{ |
171 | | -'destinationPath' = 'c:\fileName.jpg'; |
172 | | -'uri' = 'http://www.contoso.com/image.jpg'; |
173 | | -'userAgent' = '[Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer'; |
174 | | -'headers' = @{ |
175 | | -'Accept-Language' = 'en-US' |
176 | | -} |
177 | | -} |
| 169 | + expected = <<~HERE |
| 170 | + @{ |
| 171 | + 'destinationPath' = 'c:\fileName.jpg'; |
| 172 | + 'uri' = 'http://www.contoso.com/image.jpg'; |
| 173 | + 'userAgent' = '[Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer'; |
| 174 | + 'headers' = @{ |
| 175 | + 'Accept-Language' = 'en-US' |
| 176 | + } |
| 177 | + } |
178 | 178 | HERE |
179 | 179 | result = formatter.format('destinationPath' => "c:\fileName.jpg", |
180 | 180 | 'uri' => 'http://www.contoso.com/image.jpg', |
|
186 | 186 | end |
187 | 187 |
|
188 | 188 | it 'outputs correct syntax with Sensitive MSFT_Credential' do |
189 | | - expected = <<-HERE |
190 | | -@{ |
191 | | -'username' = 'jane-doe'; |
192 | | -'description' = 'Jane Doe user'; |
193 | | -'ensure' = 'present'; |
194 | | -'password' = ([PSCustomObject]@{ |
195 | | -'user' = 'jane-doe'; |
196 | | -'password' = 'password' # PuppetSensitive |
197 | | -} | new-pscredential); |
198 | | -'passwordneverexpires' = $false; |
199 | | -'disabled' = $true |
200 | | -} |
| 189 | + expected = <<~HERE |
| 190 | + @{ |
| 191 | + 'username' = 'jane-doe'; |
| 192 | + 'description' = 'Jane Doe user'; |
| 193 | + 'ensure' = 'present'; |
| 194 | + 'password' = ([PSCustomObject]@{ |
| 195 | + 'user' = 'jane-doe'; |
| 196 | + 'password' = 'password' # PuppetSensitive |
| 197 | + } | new-pscredential); |
| 198 | + 'passwordneverexpires' = $false; |
| 199 | + 'disabled' = $true |
| 200 | + } |
201 | 201 | HERE |
202 | 202 | sensitive_pass = Puppet::Pops::Types::PSensitiveType::Sensitive.new('password') |
203 | 203 | result = formatter.format('username' => 'jane-doe', |
|
0 commit comments