Skip to content

Commit a8e60d9

Browse files
committed
Fix up test
1 parent 1f63c60 commit a8e60d9

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

resources/windows_service/locales/en-us.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ queryConfigFailed = "Failed to query service configuration: %{error}"
1515
queryStatusFailed = "Failed to query service status: %{error}"
1616
openServiceFailed = "Failed to open service: %{error}"
1717
getKeyNameFailed = "Failed to resolve service name from display name: %{error}"
18-
displayNameMismatch = "Service display name mismatch: expected '%{expected}', got '%{actual}'"
1918

2019
[export]
2120
enumServicesFailed = "Failed to enumerate services: %{error}"

resources/windows_service/src/service.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,6 @@ pub fn get_service(input: &WindowsService) -> Result<WindowsService, ServiceErro
221221

222222
let svc = unsafe { read_service_state(service_handle.0, &service_key_name) }?;
223223

224-
// If both name and display_name were provided, verify they match
225-
if input.name.is_some() && let Some(expected_dn) = input.display_name.as_ref() {
226-
// let expected_dn = input.display_name.as_ref().unwrap();
227-
let actual_dn = svc.display_name.as_deref().unwrap_or("");
228-
if !actual_dn.eq_ignore_ascii_case(expected_dn) {
229-
return Err(
230-
t!("get.displayNameMismatch", expected = expected_dn, actual = actual_dn)
231-
.to_string()
232-
.into(),
233-
);
234-
}
235-
}
236224

237225
Ok(svc)
238226
}
@@ -966,11 +954,8 @@ fn matches_filter(service: &WindowsService, filter: &WindowsService) -> bool {
966954
/// that would be applied. If the service does not exist, returns the desired
967955
/// state with a single `whatIf` entry describing the failure to open it.
968956
fn what_if_set(input: &WindowsService, name: &str) -> Result<WindowsService, ServiceError> {
969-
// Look up the current state using only the service key name. Forwarding
970-
// the entire `input` here would cause `get_service` to verify any desired
971-
// `displayName` against the live service and surface a `displayNameMismatch`
972-
// error — which would defeat what-if for any change that targets the
973-
// display name.
957+
// Look up the current state using only the service key name; we want the
958+
// live values to compare against, not a re-validation of the desired ones.
974959
let lookup = WindowsService {
975960
name: Some(name.to_string()),
976961
..Default::default()

resources/windows_service/tests/windows_service_get.tests.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ Describe 'Windows Service get tests' -Skip:(!$IsWindows) {
7373
$result._exist | Should -BeTrue
7474
}
7575

76-
It 'Returns error when name and displayName do not match' {
76+
It 'Returns the live displayName when the desired displayName differs (name is authoritative)' {
7777
$json = @{ name = $knownServiceName; displayName = 'Wrong Display Name' } | ConvertTo-Json -Compress
78-
$out = $json | dsc resource get -r $resourceType -f - 2>&1
79-
$LASTEXITCODE | Should -Not -Be 0
78+
$out = $json | dsc resource get -r $resourceType -f - 2>$testdrive/error.log
79+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Raw $testdrive/error.log)
80+
$result = ($out | ConvertFrom-Json).actualState
81+
$result.name | Should -BeExactly $knownServiceName
82+
$result.displayName | Should -BeExactly $knownDisplayName
83+
$result._exist | Should -BeTrue
8084
}
8185
}
8286

0 commit comments

Comments
 (0)