@@ -14,137 +14,41 @@ import * as utils from '../src/utils';
14
14
import * as crypto from '../src/crypto' ;
15
15
use ( sinonChai ) ;
16
16
17
- const windows2022 = `
18
- Host Name: fv-az618-92
19
- OS Name: Microsoft Windows Server 2022 Datacenter
20
- OS Version: 10.0.20348 N/A Build 20348
21
- OS Manufacturer: Microsoft Corporation
22
- OS Configuration: Standalone Server
23
- OS Build Type: Multiprocessor Free
24
- Registered Owner: N/A
25
- Registered Organization: N/A
26
- Product ID: 00454-60000-00001-AA926
27
- Original Install Date: 8/8/2023, 9:08:26 AM
28
- System Boot Time: 8/9/2023, 3:13:18 PM
29
- System Manufacturer: Microsoft Corporation
30
- System Model: Virtual Machine
31
- System Type: x64-based PC
32
- Processor(s): 1 Processor(s) Installed.
33
- [01]: Intel64 Family 6 Model 79 Stepping 1 GenuineIntel ~2295 Mhz
34
- BIOS Version: American Megatrends Inc. 090008 , 12/7/2018
35
- Windows Directory: C:\\Windows
36
- System Directory: C:\\Windows\\system32
37
- Boot Device: \\Device\\HarddiskVolume1
38
- System Locale: en-us;English (United States)
39
- Input Locale: en-us;English (United States)
40
- Time Zone: (UTC) Coordinated Universal Time
41
- Total Physical Memory: 7,168 MB
42
- Available Physical Memory: 5,426 MB
43
- Virtual Memory: Max Size: 8,959 MB
44
- Virtual Memory: Available: 7,373 MB
45
- Virtual Memory: In Use: 1,586 MB
46
- Page File Location(s): D:\\pagefile.sys
47
- Domain: WORKGROUP
48
- Logon Server: \\\\fv-az618-92
49
- Hotfix(s): 5 Hotfix(s) Installed.
50
- [01]: KB5028852
51
- [02]: KB5028858
52
- [03]: KB5011048
53
- [04]: KB5028171
54
- [05]: KB5028317
55
- Network Card(s): 1 NIC(s) Installed.
56
- [01]: Microsoft Hyper-V Network Adapter
57
- Connection Name: Ethernet
58
- DHCP Enabled: Yes
59
- DHCP Server: 168.63.129.16
60
- IP address(es)
61
- [01]: 10.1.0.141
62
- [02]: fe80::deb6:64f:8300:ef77
63
- Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
64
- ` ;
65
-
66
- const windows2019 = `
67
- Host Name: fv-az276-691
68
- OS Name: Microsoft Windows Server 2019 Datacenter
69
- OS Version: 10.0.17763 N/A Build 17763
70
- OS Manufacturer: Microsoft Corporation
71
- OS Configuration: Standalone Server
72
- OS Build Type: Multiprocessor Free
73
- Registered Owner: N/A
74
- Registered Organization: N/A
75
- Product ID: 00430-00000-00000-AA138
76
- Original Install Date: 8/3/2023, 10:11:03 AM
77
- System Boot Time: 8/9/2023, 3:19:20 PM
78
- System Manufacturer: Microsoft Corporation
79
- System Model: Virtual Machine
80
- System Type: x64-based PC
81
- Processor(s): 1 Processor(s) Installed.
82
- [01]: Intel64 Family 6 Model 63 Stepping 2 GenuineIntel ~2394 Mhz
83
- BIOS Version: American Megatrends Inc. 090008 , 12/7/2018
84
- Windows Directory: C:\\Windows
85
- System Directory: C:\\Windows\\system32
86
- Boot Device: \\Device\\HarddiskVolume1
87
- System Locale: en-us;English (United States)
88
- Input Locale: en-us;English (United States)
89
- Time Zone: (UTC) Coordinated Universal Time
90
- Total Physical Memory: 7,168 MB
91
- Available Physical Memory: 5,543 MB
92
- Virtual Memory: Max Size: 8,959 MB
93
- Virtual Memory: Available: 7,426 MB
94
- Virtual Memory: In Use: 1,533 MB
95
- Page File Location(s): D:\\pagefile.sys
96
- Domain: WORKGROUP
97
- Logon Server: \\\\fv-az276-691
98
- Hotfix(s): 6 Hotfix(s) Installed.
99
- [01]: KB5028855
100
- [02]: KB4486153
101
- [03]: KB4589208
102
- [04]: KB5004424
103
- [05]: KB5028168
104
- [06]: KB5028316
105
- Network Card(s): 2 NIC(s) Installed.
106
- [01]: Hyper-V Virtual Ethernet Adapter
107
- Connection Name: vEthernet (nat)
108
- DHCP Enabled: No
109
- IP address(es)
110
- [01]: 172.27.224.1
111
- [02]: fe80::39cd:87ac:c9ad:cd5e
112
- [02]: Microsoft Hyper-V Network Adapter
113
- Connection Name: Ethernet 2
114
- DHCP Enabled: Yes
115
- DHCP Server: 168.63.129.16
116
- IP address(es)
117
- [01]: 10.1.36.0
118
- [02]: fe80::ae04:627e:a23b:d046
119
- Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
120
- ` ;
121
17
describe ( 'utils' , ( ) => {
122
18
let coreStub : SinonStubbedInstance < typeof core > ;
19
+ let platformStub : SinonStubbedInstance < typeof core . platform > ;
123
20
beforeEach ( 'stub core' , ( ) => {
21
+ platformStub = stub ( core . platform ) ;
124
22
coreStub = stub ( core ) ;
125
23
} ) ;
126
24
afterEach ( 'restore stubs' , ( ) => {
127
25
restore ( ) ;
128
26
} ) ;
129
27
describe ( '.getOsVersion()' , ( ) => {
130
- let getExecOutput : SinonStubbedMember < typeof exec . getExecOutput > ;
131
28
beforeEach ( 'stub debs' , ( ) => {
132
- getExecOutput = stub ( exec , 'getExecOutput' ) ;
133
- getExecOutput . withArgs ( 'systeminfo' ) . resolves ( {
134
- exitCode : 0 ,
135
- stdout : windows2019 ,
136
- stderr : '' ,
29
+ platformStub . getDetails . resolves ( {
30
+ name : 'Microsoft Windows Server 2019 Datacenter' ,
31
+ platform : 'win32' ,
32
+ arch : 'x64' ,
33
+ version : '10.0.17763' ,
34
+ isWindows : true ,
35
+ isMacOS : false ,
36
+ isLinux : false ,
137
37
} ) ;
138
38
} ) ;
139
39
it ( 'correctly returns for windows-2019' , async ( ) => {
140
40
const out = await utils . getOsVersion ( ) ;
141
41
expect ( out ) . to . equal ( 2019 ) ;
142
42
} ) ;
143
43
it ( 'correctly returns for windows-2022' , async ( ) => {
144
- getExecOutput . withArgs ( 'systeminfo' ) . resolves ( {
145
- exitCode : 0 ,
146
- stdout : windows2022 ,
147
- stderr : '' ,
44
+ platformStub . getDetails . resolves ( {
45
+ name : 'Microsoft Windows Server 2022 Datacenter' ,
46
+ platform : 'win32' ,
47
+ arch : 'x64' ,
48
+ version : '10.0.20348' ,
49
+ isWindows : true ,
50
+ isMacOS : false ,
51
+ isLinux : false ,
148
52
} ) ;
149
53
const out = await utils . getOsVersion ( ) ;
150
54
expect ( out ) . to . equal ( 2022 ) ;
@@ -154,30 +58,25 @@ describe('utils', () => {
154
58
await utils . getOsVersion ( ) ;
155
59
expect ( coreStub . isDebug ) . to . have . callCount ( 1 ) ;
156
60
expect ( coreStub . startGroup ) . to . have . been . calledOnceWith ( 'systeminfo' ) ;
157
- expect ( coreStub . debug ) . to . have . been . calledOnceWith ( windows2019 ) ;
61
+ expect ( coreStub . debug ) . to . have . been . calledOnceWith ( "name: Microsoft Windows Server 2019 Datacenter\nplatform: win32\narch: x64\nversion: 10.0.17763\nisWindows: true\nisMacOS: false\nisLinux: false" ) ;
158
62
expect ( coreStub . endGroup ) . to . have . callCount ( 1 ) ;
159
63
} ) ;
160
64
it ( 'fails gracefully when error is thrown' , async ( ) => {
161
65
const err = new Error ( 'synthetic error' ) ;
162
- getExecOutput . withArgs ( 'systeminfo' ) . rejects ( err ) ;
66
+ platformStub . getDetails . rejects ( err ) ;
163
67
const res = await utils . getOsVersion ( ) ;
164
68
expect ( res ) . to . equal ( null ) ;
165
69
expect ( coreStub . warning ) . to . have . been . calledOnceWithExactly ( err ) ;
166
70
} ) ;
167
71
it ( 'fails gracefully with bad output' , async ( ) => {
168
- getExecOutput . withArgs ( 'systeminfo' ) . resolves ( {
169
- exitCode : 0 ,
170
- stdout : 'os name: not a number' ,
171
- stderr : '' ,
172
- } ) ;
173
- const res = await utils . getOsVersion ( ) ;
174
- expect ( res ) . to . equal ( null ) ;
175
- } ) ;
176
- it ( 'fails gracefully with no output' , async ( ) => {
177
- getExecOutput . withArgs ( 'systeminfo' ) . resolves ( {
178
- exitCode : 0 ,
179
- stdout : '' ,
180
- stderr : '' ,
72
+ platformStub . getDetails . resolves ( {
73
+ name : 'not a number' ,
74
+ platform : 'win32' ,
75
+ arch : 'x64' ,
76
+ version : '10.0.20348' ,
77
+ isWindows : true ,
78
+ isMacOS : false ,
79
+ isLinux : false ,
181
80
} ) ;
182
81
const res = await utils . getOsVersion ( ) ;
183
82
expect ( res ) . to . equal ( null ) ;
0 commit comments