Initial
This commit is contained in:
35
server/test/compatibility.test.mjs
Normal file
35
server/test/compatibility.test.mjs
Normal file
@@ -0,0 +1,35 @@
|
||||
import './setup.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { load } from './setup.mjs';
|
||||
|
||||
const { analyzePowerShellCompatibility } = await load('../services/powershellCompatibilityService.js');
|
||||
const { normalizeOsFamily } = await load('../utils/osFamily.js');
|
||||
|
||||
test('normalizeOsFamily maps legacy and unknown host values into supported OS types', () => {
|
||||
assert.equal(normalizeOsFamily('Windows Server 2022'), 'windows');
|
||||
assert.equal(normalizeOsFamily('Ubuntu Linux'), 'linux');
|
||||
assert.equal(normalizeOsFamily('network'), 'other');
|
||||
assert.equal(normalizeOsFamily('api'), 'other');
|
||||
});
|
||||
|
||||
test('PowerShell compatibility analyzer is quiet when no Linux targets are selected', () => {
|
||||
const result = analyzePowerShellCompatibility('Get-WmiObject Win32_OperatingSystem', [{ osFamily: 'windows' }]);
|
||||
assert.equal(result.hasLinuxTargets, false);
|
||||
assert.deepEqual(result.findings, []);
|
||||
});
|
||||
|
||||
test('PowerShell compatibility analyzer flags Windows-only patterns for Linux targets', () => {
|
||||
const result = analyzePowerShellCompatibility([
|
||||
'Get-WmiObject Win32_OperatingSystem',
|
||||
'Get-Item HKLM:\\Software\\Contoso',
|
||||
'msiexec.exe /i C:\\Temp\\setup.msi',
|
||||
'dir C:\\Temp'
|
||||
].join('\n'), [{ osFamily: 'linux' }]);
|
||||
|
||||
assert.equal(result.hasLinuxTargets, true);
|
||||
assert.ok(result.findings.some((finding) => finding.id === 'wmi-or-win32-class'));
|
||||
assert.ok(result.findings.some((finding) => finding.id === 'windows-registry-provider'));
|
||||
assert.ok(result.findings.some((finding) => finding.id === 'windows-executable'));
|
||||
assert.ok(result.findings.some((finding) => finding.id === 'alias-dir'));
|
||||
});
|
||||
@@ -9,6 +9,8 @@ const {
|
||||
filterSummaryVms,
|
||||
normalizeBaseUrl,
|
||||
normalizeVCenterVm,
|
||||
previewVCenterHosts,
|
||||
settingsFromVCenterConnection,
|
||||
vmMatchesFilter
|
||||
} = await load('../services/vcenterService.js');
|
||||
|
||||
@@ -16,6 +18,27 @@ test('normalizeBaseUrl trims trailing slashes', () => {
|
||||
assert.equal(normalizeBaseUrl('https://vcenter.lab.local///'), 'https://vcenter.lab.local');
|
||||
});
|
||||
|
||||
test('standalone VMware host connections use the Web Services profile', async () => {
|
||||
const settings = settingsFromVCenterConnection({
|
||||
id: 'vc_host',
|
||||
target_type: 'host',
|
||||
base_url: 'https://esxi01.lab.local/sdk',
|
||||
username: 'root',
|
||||
password: 'secret',
|
||||
enabled: 1,
|
||||
api_mode: 'api'
|
||||
});
|
||||
|
||||
assert.equal(settings.targetType, 'host');
|
||||
assert.equal(settings.apiMode, 'web-services');
|
||||
assert.equal(settings.baseUrl, 'https://esxi01.lab.local/sdk');
|
||||
|
||||
await assert.rejects(
|
||||
() => previewVCenterHosts({ connection: { ...settings, name: 'ESXi host' } }),
|
||||
/Standalone VMware host connections/
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeVCenterVm maps guest identity and networking into a host candidate', () => {
|
||||
const candidate = normalizeVCenterVm(
|
||||
{ vm: 'vm-42', name: 'ENG-ENT-APP01', power_state: 'POWERED_ON' },
|
||||
@@ -32,6 +55,16 @@ test('normalizeVCenterVm maps guest identity and networking into a host candidat
|
||||
assert.equal(candidate.guestFullName, 'Microsoft Windows Server 2022');
|
||||
});
|
||||
|
||||
test('normalizeVCenterVm marks unknown guest operating systems as other', () => {
|
||||
const candidate = normalizeVCenterVm(
|
||||
{ vm: 'vm-unknown', name: 'MYSTERY-01', power_state: 'POWERED_ON' },
|
||||
null,
|
||||
[]
|
||||
);
|
||||
|
||||
assert.equal(candidate.osFamily, 'other');
|
||||
});
|
||||
|
||||
test('vmMatchesFilter supports hostname contains and IP equals matching', () => {
|
||||
const candidate = { name: 'ENG-ENT-APP01', fqdn: 'app01.contoso.local', address: 'app01.contoso.local', ipAddress: '10.42.1.20', ipAddresses: ['10.42.1.20'] };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user