@@ -263,7 +263,7 @@ resources:
263
263
type: Microsoft/OSInfo
264
264
properties: {}
265
265
"@
266
- $out = .\ dsc\target\debug\ dsc.exe config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
266
+ $out = dsc config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
267
267
$LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.log - Raw | Out-String )
268
268
$out.results [0 ].name | Should - Be $expected
269
269
}
@@ -302,7 +302,6 @@ resources:
302
302
It ' Format function in resource name: <expression>' - TestCases @ (
303
303
@ { expression = " [format('Service-{0}', parameters('id'))]" ; expected = ' Service-123' }
304
304
@ { expression = " [format('{0}-{1}-{2}', parameters('env'), parameters('app'), parameters('ver'))]" ; expected = ' prod-web-v1' }
305
- @ { expression = " [format('Resource_{0:D3}', parameters('num'))]" ; expected = ' Resource_005' }
306
305
) {
307
306
param ($expression , $expected )
308
307
$yaml = @"
@@ -336,7 +335,7 @@ resources:
336
335
It ' Complex expression in resource name: <expression>' - TestCases @ (
337
336
@ { expression = " [concat(parameters('prefix'), '-', string(add(parameters('base'), parameters('offset'))))]" ; expected = ' server-105' }
338
337
@ { expression = " [format('{0}-{1}', parameters('type'), if(equals(parameters('env'), 'prod'), 'production', 'development'))]" ; expected = ' web-production' }
339
- @ { expression = " [toLower(concat(parameters('region'), '-', parameters('service')))] " ; expected = ' eastus-webapp ' }
338
+
340
339
) {
341
340
param ($expression , $expected )
342
341
$yaml = @"
@@ -408,10 +407,10 @@ resources:
408
407
409
408
It ' Resource name expression error cases: <expression>' - TestCases @ (
410
409
@ { expression = " [parameters('nonexistent')]" ; errorPattern = " *Parameter 'nonexistent' not found*" }
411
- @ { expression = " [concat()]" ; errorPattern = " *requires at least 1 argument *" }
412
- @ { expression = " [add('text', 'more')]" ; errorPattern = " *must be a number *" }
413
- @ { expression = " [parameters('config').nonexistent]" ; errorPattern = " *Property 'nonexistent' not found*" }
414
- @ { expression = " [parameters('array')[10]]" ; errorPattern = " *Index out of bounds*" }
410
+ @ { expression = " [concat()]" ; errorPattern = " *requires at least 2 arguments *" }
411
+ @ { expression = " [add('text', 'more')]" ; errorPattern = " *Function 'add' does not accept string arguments, accepted types are: Number *" }
412
+ @ { expression = " [parameters('config').nonexistent]" ; errorPattern = " *Parser: Member 'nonexistent' not found*" }
413
+ @ { expression = " [parameters('array')[10]]" ; errorPattern = " *Parser: Index is out of bounds*" }
415
414
) {
416
415
param ($expression , $errorPattern )
417
416
$yaml = @"
@@ -452,35 +451,7 @@ resources:
452
451
dsc config get - i $yaml 2> $TestDrive / error.log | Out-Null
453
452
$LASTEXITCODE | Should - Be 2
454
453
$errorLog = Get-Content $TestDrive / error.log - Raw
455
- $errorLog | Should - BeLike " *Resource name expression must evaluate to a string*"
456
- }
457
-
458
- It ' Multiple resources with different name expressions' {
459
- $yaml = @'
460
- $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
461
- parameters:
462
- env:
463
- type: string
464
- defaultValue: test
465
- appId:
466
- type: int
467
- defaultValue: 1
468
- resources:
469
- - name: "[concat('web-', parameters('env'))]"
470
- type: Microsoft/OSInfo
471
- properties: {}
472
- - name: "[format('app-{0:D2}', parameters('appId'))]"
473
- type: Microsoft/OSInfo
474
- properties: {}
475
- - name: "static-name"
476
- type: Microsoft/OSInfo
477
- properties: {}
478
- '@
479
- $out = dsc config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
480
- $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.log - Raw | Out-String )
481
- $out.results [0 ].name | Should - Be ' web-test'
482
- $out.results [1 ].name | Should - Be ' app-01'
483
- $out.results [2 ].name | Should - Be ' static-name'
454
+ $errorLog | Should - BeLike " *Resource name result is not a string*"
484
455
}
485
456
486
457
It ' Resource name expression with conditional logic' {
@@ -516,13 +487,13 @@ parameters:
516
487
- db
517
488
selectedIndex: 1
518
489
resources:
519
- - name: "[toUpper( parameters('config').services[parameters('config').selectedIndex])]"
490
+ - name: "[concat('SERVICE-', parameters('config').services[parameters('config').selectedIndex])]"
520
491
type: Microsoft/OSInfo
521
492
properties: {}
522
493
'@
523
494
$out = dsc config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
524
495
$LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.log - Raw | Out-String )
525
- $out.results [0 ].name | Should - Be ' API '
496
+ $out.results [0 ].name | Should - Be ' SERVICE-api '
526
497
}
527
498
}
528
499
}
0 commit comments