@@ -48,61 +48,61 @@ Describe "Log-Rotate" -Tag 'Unit' {
48
48
49
49
Context ' Invalid parameters (Non-Terminating)' {
50
50
51
- $eaPreference = ' Continue'
51
+ $ErrorActionPreference = ' Continue'
52
52
53
53
It ' errors when config is null' {
54
54
$invalidConfig = $null
55
55
56
- $err = Log- Rotate - Config $invalidConfig - ErrorAction $eaPreference 2>&1
56
+ $err = Log- Rotate - Config $invalidConfig - ErrorVariable err 2>&1
57
57
$err | ? { $_ -is [System.Management.Automation.ErrorRecord ] } | % { $_.Exception.Message } | Should - Contain " No config file(s) specified."
58
58
}
59
59
60
60
It ' errors when config is an non-existing file' {
61
61
$invalidConfig = ' foo'
62
62
Mock Test-Path { $false }
63
63
64
- $err = Log- Rotate - Config $invalidConfig - ErrorAction $eaPreference 2>&1
64
+ $err = Log- Rotate - Config $invalidConfig 2>&1
65
65
$err | ? { $_ -is [System.Management.Automation.ErrorRecord ] } | % { $_.Exception.Message } | Should - Contain " Invalid config path specified: $invalidConfig "
66
66
}
67
67
68
68
It ' errors when configAsString is null' {
69
69
$invalidConfigAsString = $null
70
70
71
- $err = Log- Rotate - ConfigAsString $invalidConfigAsString - ErrorAction $eaPreference 2>&1
71
+ $err = Log- Rotate - ConfigAsString $invalidConfigAsString 2>&1
72
72
$err | ? { $_ -is [System.Management.Automation.ErrorRecord ] } | % { $_.Exception.Message } | Should - Contain " No config file(s) specified."
73
73
}
74
74
}
75
75
76
76
Context ' Invalid parameters (Terminating)' {
77
77
78
- $eaPreference = ' Stop'
78
+ $ErrorActionPreference = ' Stop'
79
79
80
80
It ' errors when config is null' {
81
81
$invalidConfig = $null
82
82
83
- { Log- Rotate - Config $invalidConfig - ErrorAction $eaPreference 2> $null } | Should - Throw " No config file(s) specified."
83
+ { Log- Rotate - Config $invalidConfig 2> $null } | Should - Throw " No config file(s) specified."
84
84
}
85
85
86
86
It ' errors when config is an non-existing file' {
87
87
$invalidConfig = ' foo'
88
88
Mock Test-Path { $false }
89
89
6
90
- { Log- Rotate - Config $invalidConfig - ErrorAction $eaPreference 2> $null } | Should - Throw " Invalid config path specified: $invalidConfig "
90
+ { Log- Rotate - Config $invalidConfig 2> $null } | Should - Throw " Invalid config path specified: $invalidConfig "
91
91
}
92
92
93
93
It ' errors when configAsString is null' {
94
94
$invalidConfigAsString = $null
95
95
96
- { Log- Rotate - ConfigAsString $invalidConfigAsString - ErrorAction $eaPreference 2> $null } | Should - Throw " No config file(s) specified."
96
+ { Log- Rotate - ConfigAsString $invalidConfigAsString 2> $null } | Should - Throw " No config file(s) specified."
97
97
}
98
98
}
99
99
100
100
Context ' Functionality' {
101
101
102
- $eaPreference = ' Stop'
102
+ $ErrorActionPreference = ' Stop'
103
103
104
104
It ' shows the help' {
105
- $help = Log- Rotate - Help - ErrorAction $eaPreference
105
+ $help = Log- Rotate - Help
106
106
107
107
$help | Should -Not - Be $null
108
108
}
@@ -111,7 +111,7 @@ Describe "Log-Rotate" -Tag 'Unit' {
111
111
. $initScriptBlock
112
112
Mock Compile- Full- Config {}
113
113
114
- Log- Rotate - config $configFile - ErrorAction $eaPreference
114
+ Log- Rotate - config $configFile
115
115
116
116
Assert-MockCalled Compile- Full- Config - Times 1
117
117
}
@@ -121,7 +121,7 @@ Describe "Log-Rotate" -Tag 'Unit' {
121
121
Mock Test-Path - ParameterFilter { $Path -eq ' foo' -and $PathType } { $false }
122
122
Mock Compile- Full- Config {}
123
123
124
- Log- Rotate - config $configFile - ErrorAction $eaPreference
124
+ Log- Rotate - config $configFile
125
125
126
126
Assert-MockCalled Compile- Full- Config - Times 1
127
127
}
@@ -130,7 +130,7 @@ Describe "Log-Rotate" -Tag 'Unit' {
130
130
. $initScriptBlock
131
131
Mock Validate- Full- Config {}
132
132
133
- Log- Rotate - config $configFile - ErrorAction $eaPreference
133
+ Log- Rotate - config $configFile
134
134
135
135
Assert-MockCalled Validate- Full- Config - Times 1
136
136
}
@@ -151,23 +151,23 @@ Describe "Log-Rotate" -Tag 'Unit' {
151
151
$BlockFactory
152
152
}
153
153
154
- Log- Rotate - config $configFile - ErrorAction $eaPreference
154
+ Log- Rotate - config $configFile
155
155
156
156
Assert-MockCalled New-BlockFactory - Times 1
157
157
}
158
158
159
159
It ' instantiates singleton LogFactory' {
160
160
. $initScriptBlock
161
161
162
- Log- Rotate - config $configFile - ErrorAction $eaPreference
162
+ Log- Rotate - config $configFile
163
163
164
164
Assert-MockCalled New-LogFactory - Times 1
165
165
}
166
166
167
167
It ' instantiates singleton LogObject' {
168
168
. $initScriptBlock
169
169
170
- Log- Rotate - config $configFile - ErrorAction $eaPreference
170
+ Log- Rotate - config $configFile
171
171
172
172
Assert-MockCalled New-LogObject - Times 1
173
173
}
@@ -190,7 +190,7 @@ Describe "Log-Rotate" -Tag 'Unit' {
190
190
$BlockFactory
191
191
}
192
192
193
- $result = Log- Rotate - config $configFile - ErrorAction $eaPreference
193
+ $result = Log- Rotate - config $configFile
194
194
195
195
$result | Should - Be ' create'
196
196
}
@@ -206,15 +206,15 @@ Describe "Log-Rotate" -Tag 'Unit' {
206
206
$LogFactory
207
207
}
208
208
209
- $result = Log- Rotate - config $configFile - ErrorAction $eaPreference
209
+ $result = Log- Rotate - config $configFile
210
210
211
211
$result | Should - Be ' initstatus'
212
212
}
213
213
214
214
It ' processes a block configuration' {
215
215
. $initScriptBlock
216
216
217
- Log- Rotate - config $configFile - ErrorAction $eaPreference
217
+ Log- Rotate - config $configFile
218
218
219
219
Assert-MockCalled Process - Local- Block - Times 1
220
220
}
@@ -231,9 +231,31 @@ Describe "Log-Rotate" -Tag 'Unit' {
231
231
$LogFactory
232
232
}
233
233
234
- $result = Log- Rotate - config $configFile - ErrorAction $eaPreference
234
+ $result = Log- Rotate - config $configFile
235
235
236
236
$result | Should - Be ' dumpstatus'
237
237
}
238
+
239
+ It ' Throws no exception only when specified' {
240
+ . $initScriptBlock
241
+ Mock Process - Local- Block {
242
+ Write-Error ' foo' - ErrorAction Continue
243
+ }
244
+
245
+ # Expect no exception
246
+ $err = Log- Rotate - config $configFile - ErrorAction Continue 2>&1
247
+ $err | ? { $_ -is [System.Management.Automation.ErrorRecord ] } | % { $_.Exception.Message } | Should - Be ' foo'
248
+ }
249
+
250
+ It ' Throws exception only when specified' {
251
+ . $initScriptBlock
252
+ Mock Process - Local- Block {
253
+ Write-Error ' foo' - ErrorAction Stop
254
+ }
255
+
256
+ # Expect exception
257
+ { Log- Rotate - config $configFile - ErrorAction Stop } | Should - Throw ' foo'
258
+ }
259
+
238
260
}
239
261
}
0 commit comments