Skip to content

Commit a658162

Browse files
committed
Fix error message when duplicate resource names are detected
1 parent 48c7687 commit a658162

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

dsc/tests/dsc_config_test.tests.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,28 @@ Describe 'dsc config test tests' {
6161
$out.results[0].result.differingProperties | Should -Be @('valueOne', 'valueTwo')
6262
}
6363
}
64+
65+
It 'Duplicate resource names are not allowed' {
66+
$configYaml = @'
67+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
68+
resources:
69+
- name: MyTest
70+
type: Microsoft.DSC.Debug/Echo
71+
properties:
72+
output: 1
73+
- name: Test2
74+
type: Microsoft.DSC.Debug/Echo
75+
properties:
76+
output: 2
77+
- name: MyTest
78+
type: Microsoft.DSC.Debug/Echo
79+
properties:
80+
output: 2
81+
'@
82+
83+
$null = dsc config test -i $configYaml 2> "$TestDrive/trace.log"
84+
$LASTEXITCODE | Should -Be 2
85+
$log = Get-Content "$TestDrive/trace.log" -Raw
86+
$log | Should -Match ".*Resource named 'MyTest' is specified more than once.*" -Because ($log | Out-String)
87+
}
6488
}

dsc_lib/src/configure/depends_on.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn get_resource_invocation_order(config: &Configuration, parser: &mut Statem
2929
for resource in &config.resources {
3030
// validate that the resource isn't specified more than once in the config
3131
if config.resources.iter().filter(|r| r.name == resource.name && r.resource_type == resource.resource_type).count() > 1 {
32-
return Err(DscError::Validation(t!("configure.dependsOn.duplicateResource", resource_name = resource.name).to_string()));
32+
return Err(DscError::Validation(t!("configure.dependsOn.duplicateResource", name = resource.name).to_string()));
3333
}
3434

3535
let mut dependency_already_in_order = true;

0 commit comments

Comments
 (0)