@@ -246,22 +246,20 @@ Describe 'tests for function expressions' {
246
246
}
247
247
248
248
It ' utcNow function works for: utcNow(<format>)' - TestCases @ (
249
- @ { format = $null }
250
- @ { format = " yyyy-MM-dd" }
251
- @ { format = " yyyy-MM-ddTHH" }
252
- @ { format = " yyyy-MM-ddTHHZ" }
253
- @ { format = " MMM dd, yyyy HH" }
254
- @ { format = " yy-MMMM-dddd tt H" }
255
- @ { format = " MMM ddd zzz" }
256
- @ { format = " YY YYYY MM MMM MMMM" }
249
+ @ { format = $null ; regex = ' ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}Z$' }
250
+ @ { format = " yyyy-MM-dd" ; regex = ' ^\d{4}-\d{2}-\d{2}$' }
251
+ @ { format = " yyyy-MM-ddTHH" ; regex = ' ^\d{4}-\d{2}-\d{2}T\d{2}$' }
252
+ @ { format = " yyyy-MM-ddTHHZ" ; regex = ' ^\d{4}-\d{2}-\d{2}T\d{2}Z$' }
253
+ @ { format = " MMM dd, yyyy HH" ; regex = ' ^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{2}, \d{4} \d{2}$' }
254
+ @ { format = " yy-MMMM-dddd tt H" ; regex = ' ^\d{2}-(January|February|March|April|May|June|July|August|September|October|November|December)-(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday) (AM|PM) \d+$' }
255
+ @ { format = " MMM ddd zzz" ; regex = ' ^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (Sun|Mon|Tue|Wed|Thu|Fri|Sat) \+00:00$' }
256
+ @ { format = " yy yyyy MM MMM MMMM" ; regex = ' ^\d{2} \d{4} \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (January|February|March|April|May|June|July|August|September|October|November|December)$' }
257
+ @ { format = " yyyy-MM-ddTHH:mm:ss" ; regex = ' ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$' }
257
258
) {
258
- param ($format )
259
+ param ($format , $regex )
259
260
260
- if ($null -eq $format ) {
261
- $expected = (Get-Date - AsUTC).ToString(" o" )
262
- } else {
263
- $expected = (Get-Date - AsUTC).ToString($format )
264
- $format = " '$format '"
261
+ if ($null -ne $format ) {
262
+ $format = " '$format '"
265
263
}
266
264
267
265
$config_yaml = @"
@@ -281,10 +279,8 @@ Describe 'tests for function expressions' {
281
279
# ConvertFrom-Json will convert the date to a DateTime object, so we use regex to capture the string
282
280
$out -match ' "output":"(?<date>.*?)"' | Should - BeTrue - Because " Output should contain a date"
283
281
$actual = $matches [' date' ]
284
- # since the datetimes might slightly differ, we remove the seconds and milliseconds
285
- $expected = $expected -replace ' :\d+\.\d+Z$' , ' Z'
286
- $actual = $actual -replace ' :\d+\.\d+Z$' , ' Z'
287
- $actual | Should - BeExactly $expected - Because " Expected: '$expected ', Actual: '$actual '"
282
+ # comapre against the regex
283
+ $actual | Should -Match $regex - Because " Output date '$actual ' should match regex '$regex '"
288
284
}
289
285
290
286
It ' utcNow errors if used not as a parameter default' {
@@ -298,6 +294,7 @@ Describe 'tests for function expressions' {
298
294
"@
299
295
$out = dsc - l trace config get - i $config_yaml 2> $TestDrive / error.log | ConvertFrom-Json
300
296
$LASTEXITCODE | Should - Be 2 - Because (Get-Content $TestDrive / error.log - Raw)
297
+ $out | Should - BeNullOrEmpty - Because " Output should be null or empty"
301
298
(Get-Content $TestDrive / error.log - Raw) | Should -Match ' utcNow function can only be used as a parameter default'
302
299
}
303
300
0 commit comments