use super::*;
fn blank() -> Probes {
Probes {
status: Run::Failed,
version: Run::Failed,
lxss_service: None,
wsl_service: None,
vm_platform: None,
wsl_feature: None,
hypervisor: None,
reboot_pending: None,
renames_pending: None,
installed_this_boot: false,
restarted_for_wsl: false,
}
}
fn win11_without_wsl() -> Probes {
Probes {
lxss_service: Some(false),
wsl_service: Some(false),
vm_platform: Some(Feature::Disabled),
wsl_feature: Some(Feature::Disabled),
hypervisor: Some(false),
reboot_pending: Some(false),
renames_pending: Some(false),
..blank()
}
}
fn win11_store_ready() -> Probes {
Probes {
status: Run::Ok,
version: Run::Ok,
wsl_service: Some(true),
vm_platform: Some(Feature::Enabled),
hypervisor: Some(true),
..win11_without_wsl()
}
}
fn win10_inbox_ready() -> Probes {
Probes {
status: Run::Ok,
version: Run::Failed,
lxss_service: Some(true),
wsl_service: Some(false),
vm_platform: Some(Feature::Enabled),
wsl_feature: Some(Feature::Enabled),
hypervisor: Some(true),
reboot_pending: Some(false),
renames_pending: Some(false),
installed_this_boot: false,
restarted_for_wsl: false,
}
}
fn firmware_off() -> Probes {
Probes {
status: Run::Failed,
hypervisor: Some(false),
renames_pending: Some(true),
..win11_store_ready()
}
}
#[test]
fn a_machine_without_wsl_is_missing() {
assert_eq!(classify(&win11_without_wsl()), Missing);
assert_eq!(
classify(&Probes {
status: Run::Missing,
version: Run::Missing,
..win11_without_wsl()
}),
Missing
);
assert_eq!(
classify(&Probes {
vm_platform: None,
wsl_feature: None,
hypervisor: None,
..win11_without_wsl()
}),
Missing
);
assert_eq!(
classify(&Probes {
reboot_pending: Some(true),
renames_pending: Some(true),
..win11_without_wsl()
}),
Missing
);
}
#[test]
fn wsl_on_and_running_is_ready() {
assert_eq!(classify(&win11_store_ready()), Ready);
assert_eq!(classify(&win10_inbox_ready()), Ready);
assert_eq!(
classify(&Probes {
status: Run::Failed,
..win11_store_ready()
}),
Ready
);
assert_eq!(
classify(&Probes {
status: Run::TimedOut,
version: Run::TimedOut,
..win11_store_ready()
}),
Ready
);
assert_eq!(
classify(&Probes {
vm_platform: None,
wsl_feature: None,
hypervisor: None,
..win11_store_ready()
}),
Ready
);
assert_eq!(
classify(&Probes {
reboot_pending: Some(true),
renames_pending: Some(true),
..win11_store_ready()
}),
Ready
);
assert_eq!(
classify(&Probes {
renames_pending: Some(true),
..win10_inbox_ready()
}),
Ready
);
}
#[test]
fn a_pending_update_doesnt_hide_a_store_wsl_without_a_distribution() {
let store = Probes {
status: Run::Failed,
reboot_pending: Some(true),
..win11_store_ready()
};
assert_eq!(classify(&store), Ready);
assert_eq!(
classify(&Probes {
version: Run::TimedOut,
..store
}),
Ready
);
let inbox = Probes {
status: Run::Failed,
reboot_pending: Some(true),
..win10_inbox_ready()
};
assert_eq!(classify(&inbox), NeedsReboot);
}
#[test]
fn unreadable_servicing_is_no_proof_nothing_is_pending() {
let unread = Probes {
vm_platform: None,
wsl_feature: None,
hypervisor: None,
reboot_pending: None,
..win11_store_ready()
};
assert_eq!(classify(&unread), Unknown);
assert_eq!(
classify(&Probes {
reboot_pending: Some(false),
..unread
}),
Ready
);
}
#[test]
fn turned_on_but_not_restarted_needs_a_reboot() {
let after_install = Probes {
status: Run::Failed,
version: Run::Ok,
wsl_service: Some(true),
vm_platform: Some(Feature::Enabled),
hypervisor: Some(false),
reboot_pending: Some(true),
installed_this_boot: true,
..win11_without_wsl()
};
assert_eq!(classify(&after_install), NeedsReboot);
assert_eq!(
classify(&Probes {
hypervisor: Some(true),
status: Run::Ok,
..after_install
}),
NeedsReboot
);
assert_eq!(
classify(&Probes {
hypervisor: Some(true),
reboot_pending: Some(false),
renames_pending: Some(true),
..after_install
}),
NeedsReboot
);
let reopened = Probes {
vm_platform: Some(Feature::Disabled),
wsl_feature: Some(Feature::Disabled),
wsl_service: Some(false),
version: Run::Failed,
..after_install
};
assert_eq!(classify(&reopened), NeedsReboot);
assert_eq!(
classify(&Probes {
reboot_pending: None,
..reopened
}),
NeedsReboot
);
let by_hand = Probes {
status: Run::Failed,
vm_platform: Some(Feature::Enabled),
wsl_feature: Some(Feature::Enabled),
lxss_service: Some(false),
hypervisor: Some(false),
reboot_pending: Some(true),
..win11_without_wsl()
};
assert_eq!(classify(&by_hand), NeedsReboot);
}
#[test]
fn our_install_that_changed_nothing_is_judged_on_the_rest() {
assert_eq!(
classify(&Probes {
installed_this_boot: true,
..win11_store_ready()
}),
Ready
);
}
#[test]
fn virtualization_off_in_the_firmware_never_loops_on_restarts() {
let off = firmware_off();
assert_eq!(classify(&off), Unknown);
assert!(virtualization_off(&off, classify(&off)));
let after_ours = Probes {
restarted_for_wsl: true,
reboot_pending: Some(true),
..off
};
assert_eq!(classify(&after_ours), Unknown);
assert!(virtualization_off(&after_ours, classify(&after_ours)));
let before_ours = Probes {
reboot_pending: Some(true),
..off
};
assert_eq!(classify(&before_ours), NeedsReboot);
assert!(!virtualization_off(&before_ours, NeedsReboot));
assert_eq!(
classify(&Probes {
installed_this_boot: true,
..after_ours
}),
NeedsReboot
);
assert!(!virtualization_off(&win11_store_ready(), Ready));
}
#[test]
fn what_the_signals_cant_settle_is_unknown() {
assert_eq!(classify(&blank()), Unknown);
assert_eq!(
classify(&Probes {
status: Run::TimedOut,
version: Run::TimedOut,
..blank()
}),
Unknown
);
assert_eq!(
classify(&Probes {
status: Run::TimedOut,
..win11_without_wsl()
}),
Unknown
);
let no_hypervisor = Probes {
hypervisor: Some(false),
..win10_inbox_ready()
};
assert_eq!(classify(&no_hypervisor), Unknown);
assert!(virtualization_off(&no_hypervisor, Unknown));
assert_eq!(
classify(&Probes {
vm_platform: Some(Feature::Enabled),
..win11_without_wsl()
}),
Unknown
);
}
#[test]
fn wsl_1_without_the_platform_is_missing_wsl_2() {
let wsl1 = Probes {
vm_platform: Some(Feature::Disabled),
hypervisor: Some(false),
..win10_inbox_ready()
};
assert_eq!(classify(&wsl1), Missing);
assert_eq!(
classify(&Probes {
reboot_pending: Some(true),
..wsl1
}),
Missing
);
assert_eq!(
classify(&Probes {
reboot_pending: Some(true),
installed_this_boot: true,
..wsl1
}),
NeedsReboot
);
}
#[test]
fn a_store_wsl_without_the_platform_and_an_updates_restart_pending_is_missing() {
let store_without_platform = Probes {
version: Run::Ok,
wsl_service: Some(true),
reboot_pending: Some(true),
renames_pending: Some(true),
..win11_without_wsl()
};
assert_eq!(classify(&store_without_platform), Missing);
}
#[test]
fn the_wmi_output_is_read_by_key() {
let out = "features=ok\r\nfeature:VirtualMachinePlatform=1\r\nfeature:Microsoft-Windows-Subsystem-Linux=2\r\nhypervisor=True\r\n";
assert_eq!(parse_cim(out), (Some(Feature::Enabled), Some(Feature::Disabled), Some(true)));
assert_eq!(
parse_cim("features=ok\nfeature:VirtualMachinePlatform=3\nhypervisor=False\n"),
(Some(Feature::Absent), Some(Feature::Absent), Some(false))
);
assert_eq!(parse_cim("hypervisor=False\n"), (None, None, Some(false)));
assert_eq!(
parse_cim("features=ok\nfeature:VirtualMachinePlatform=4\nfeature:Microsoft-Windows-Subsystem-Linux=1"),
(None, Some(Feature::Enabled), None)
);
assert_eq!(parse_cim(""), (None, None, None));
}