Skip to content

Commit bf30a54

Browse files
committed
fix tests and copilot feedback
1 parent e9bbe0f commit bf30a54

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

dsc/src/util.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,9 @@ pub fn get_input(input: Option<&String>, file: Option<&String>, parameters_from_
498498
// see if an extension should handle this file
499499
let mut discovery = Discovery::new();
500500
for extension in discovery.get_extensions(&Capability::Import) {
501-
let Ok(content) = extension.import(path) else {
502-
continue;
503-
};
504-
return content;
501+
if let Ok(content) = extension.import(path) {
502+
return content;
503+
}
505504
}
506505
match std::fs::read_to_string(path) {
507506
Ok(input) => {

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ Describe 'Discover extension tests' {
1515
It 'Discover extensions' {
1616
$out = dsc extension list | ConvertFrom-Json
1717
$LASTEXITCODE | Should -Be 0
18-
$out.Count | Should -Be 1
19-
$out.type | Should -BeExactly 'Test/Discover'
20-
$out.version | Should -BeExactly '0.1.0'
21-
$out.capabilities | Should -BeExactly @('discover')
22-
$out.manifest | Should -Not -BeNullOrEmpty
18+
$out.Count | Should -Be 2 -Because ($out | Out-String)
19+
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
20+
$out[0].version | Should -Be '0.1.0'
21+
$out[0].capabilities | Should -BeExactly @('import')
22+
$out[0].manifest | Should -Not -BeNullOrEmpty
23+
$out[1].type | Should -BeExactly 'Test/Discover'
24+
$out[1].version | Should -BeExactly '0.1.0'
25+
$out[1].capabilities | Should -BeExactly @('discover')
26+
$out[1].manifest | Should -Not -BeNullOrEmpty
2327
}
2428

2529
It 'Filtering works for extension discovered resources' {

dsc_lib/locales/en-us.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ extensionReturnedSecret = "Extension '%{extension}' returned secret"
186186
extensionReturnedNoSecret = "Extension '%{extension}' did not return a secret"
187187
secretNoResults = "Extension '%{extension}' returned no output"
188188
importingFile = "Importing file '%{file}' with extension '%{extension}'"
189+
importNotSupported = "Import is not supported by extension '%{extension}' for file '%{file}'"
190+
importNoResults = "Extension '%{extension}' returned no results for import"
189191

190192
[extensions.extension_manifest]
191193
extensionManifestSchemaTitle = "Extension manifest schema URI"
@@ -456,3 +458,4 @@ foundSetting = "Found setting '%{name}' in %{path}"
456458
notFoundSetting = "Setting '%{name}' not found in %{path}"
457459
failedToGetExePath = "Can't get 'dsc' executable path"
458460
settingNotFound = "Setting '%{name}' not found"
461+
failedToAbsolutizePath = "Failed to absolutize path '%{path}'"

dsc_lib/src/extensions/dscextension.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ impl DscExtension {
152152
pub fn import(&self, file: &str) -> Result<String, DscError> {
153153
if self.capabilities.contains(&Capability::Import) {
154154
let file_path = Path::new(file);
155-
if self.import_extensions.as_ref().is_some_and(|exts| exts.contains(&file_path.extension().and_then(|s| s.to_str()).unwrap_or_default().to_string())) {
155+
let file_extension = file_path.extension().and_then(|s| s.to_str()).unwrap_or_default().to_string();
156+
if self.import_extensions.as_ref().is_some_and(|exts| exts.contains(&file_extension)) {
156157
debug!("{}", t!("extensions.dscextension.importingFile", file = file, extension = self.type_name));
157158
} else {
158159
debug!("{}", t!("extensions.dscextension.importNotSupported", file = file, extension = self.type_name));
@@ -267,7 +268,7 @@ fn process_import_args(args: Option<&Vec<ImportArgKind>>, file: &str) -> Result<
267268
// make path absolute
268269
let path = Path::new(file);
269270
let Ok(full_path) = path.absolutize() else {
270-
return Err(DscError::Extension(t!("util.failedToAbsolutizePath").to_string()));
271+
return Err(DscError::Extension(t!("util.failedToAbsolutizePath", path = path : {:?}).to_string()));
271272
};
272273

273274
let mut processed_args = Vec::<String>::new();

extensions/bicep/bicep.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,19 @@ Describe 'Bicep extension tests' -Skip:(!$foundBicep) {
1717
$out.results[0].result.actualState.output | Should -BeExactly 'Hello, world!'
1818
(Get-Content -Path $TestDrive/error.log -Raw) | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
1919
}
20+
21+
It 'Invalid bicep file returns error' {
22+
$bicepFile = "$TestDrive/invalid.bicep"
23+
Set-Content -Path $bicepFile -Value @"
24+
myresource invalid 'Microsoft.DSC.Extension/Bicep:1.0' = {
25+
name: 'invalid'
26+
properties: {
27+
output: 'This is invalid'
28+
"@
29+
$out = dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
30+
$LASTEXITCODE | Should -Be 4 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
31+
$content = (Get-Content -Path $TestDrive/error.log -Raw)
32+
$content | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
33+
$content | Should -Match "BCP279: Expected a type at this location"
34+
}
2035
}

0 commit comments

Comments
 (0)