2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'package:flutter_tools/src/base/os.dart' ;
5
6
import 'package:flutter_tools/src/doctor_validator.dart' ;
6
7
import 'package:flutter_tools/src/windows/windows_version_validator.dart' ;
8
+ import 'package:test/fake.dart' ;
7
9
8
10
import '../src/common.dart' ;
9
- import '../src/fake_process_manager.dart' ;
10
11
11
- /// Example output from `systeminfo` from a Windows 10 host
12
- const String validWindows10StdOut = r'''
13
- Host Name: XXXXXXXXXXXX
14
- OS Name: Microsoft Windows 10 Enterprise
15
- OS Version: 10.0.19044 N/A Build 19044
16
- OS Manufacturer: Microsoft Corporation
17
- OS Configuration: Member Workstation
18
- OS Build Type: Multiprocessor Free
19
- Registered Owner: N/A
20
- Registered Organization: N/A
21
- Product ID: XXXXXXXXXXXX
22
- Original Install Date: 8/4/2022, 2:51:28 PM
23
- System Boot Time: 8/10/2022, 1:03:10 PM
24
- System Manufacturer: Google
25
- System Model: Google Compute Engine
26
- System Type: x64-based PC
27
- Processor(s): 1 Processor(s) Installed.
28
- [01]: AMD64 Family 23 Model 49 Stepping 0 AuthenticAMD ~2250 Mhz
29
- BIOS Version: Google Google, 6/29/2022
30
- Windows Directory: C:\\Windows
31
- System Directory: C:\\Windows\\system32
32
- Boot Device: \\Device\\HarddiskVolume2
33
- System Locale: en-us;English (United States)
34
- Input Locale: en-us;English (United States)
35
- Time Zone: (UTC-08:00) Pacific Time (US & Canada)
36
- Total Physical Memory: 32,764 MB
37
- Available Physical Memory: 17,852 MB
38
- Virtual Memory: Max Size: 33,788 MB
39
- Virtual Memory: Available: 18,063 MB
40
- Virtual Memory: In Use: 15,725 MB
41
- Page File Location(s): C:\\pagefile.sys
42
- Domain: ad.corp.google.com
43
- Logon Server: \\CBF-DC-8
44
- Hotfix(s): 7 Hotfix(s) Installed.
45
- [01]: KB5013624
46
- [02]: KB5003791
47
- [03]: KB5012170
48
- [04]: KB5016616
49
- [05]: KB5014032
50
- [06]: KB5014671
51
- [07]: KB5015895
52
- Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
53
- ''' ;
54
-
55
- const String validWindows11CnStdOut = r'''
56
- 主机名: XXXXXXXXXXXX
57
- OS 名称: Microsoft Windows 11 专业版
58
- OS 版本: 10.0.22621 暂缺 Build 22621
59
- OS 制造商: Microsoft Corporation
60
- OS 配置: 独立工作站
61
- OS 构建类型: Multiprocessor Free
62
- 注册的所有人: 暂缺
63
- 注册的组织: 暂缺
64
- 产品 ID: XXXXXXXXXXXX
65
- 初始安装日期: 2022/11/9, 13:33:50
66
- 系统启动时间: 2022/11/30, 13:36:47
67
- 系统制造商: ASUS
68
- 系统型号: System Product Name
69
- 系统类型: x64-based PC
70
- 处理器: 安装了 1 个处理器。
71
- [01]: Intel64 Family 6 Model 151 Stepping 2 GenuineIntel ~3600 Mhz
72
- BIOS 版本: American Megatrends Inc. 2103, 2022/9/30
73
- Windows 目录: C:\WINDOWS
74
- 系统目录: C:\WINDOWS\system32
75
- 启动设备: \Device\HarddiskVolume1
76
- 系统区域设置: zh-cn;中文(中国)
77
- 输入法区域设置: zh-cn;中文(中国)
78
- 时区: (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐
79
- 物理内存总量: 65,277 MB
80
- 可用的物理内存: 55,333 MB
81
- 虚拟内存: 最大值: 75,005 MB
82
- 虚拟内存: 可用: 61,781 MB
83
- 虚拟内存: 使用中: 13,224 MB
84
- 页面文件位置: C:\pagefile.sys
85
- 域: WORKGROUP
86
- 登录服务器: \\XXXXXXXXXXXX
87
- 修补程序: 安装了 3 个修补程序。
88
- [01]: KB5020622
89
- [02]: KB5019980
90
- [03]: KB5019304
91
- Hyper-V 要求: 已检测到虚拟机监控程序。将不显示 Hyper-V 所需的功能。
92
- ''' ;
12
+ /// Fake [_WindowsUtils] to use for testing
13
+ class FakeValidOperatingSystemUtils extends Fake
14
+ implements OperatingSystemUtils {
15
+ FakeValidOperatingSystemUtils (
16
+ [this .name = 'Microsoft Windows [Version 11.0.22621.963]' ]);
93
17
94
- /// Example output from `systeminfo` from version != 10
95
- const String invalidWindowsStdOut = r'''
96
- Host Name: XXXXXXXXXXXX
97
- OS Name: Microsoft Windows 8.1 Enterprise
98
- OS Version: 6.3.9600 Build 9600
99
- OS Manufacturer: Microsoft Corporation
100
- OS Configuration: Member Workstation
101
- OS Build Type: Multiprocessor Free
102
- Registered Owner: N/A
103
- Registered Organization: N/A
104
- Product ID: XXXXXXXXXXXX
105
- Original Install Date: 8/4/2022, 2:51:28 PM
106
- System Boot Time: 8/10/2022, 1:03:10 PM
107
- System Manufacturer: Google
108
- System Model: Google Compute Engine
109
- System Type: x64-based PC
110
- Processor(s): 1 Processor(s) Installed.
111
- [01]: AMD64 Family 23 Model 49 Stepping 0 AuthenticAMD ~2250 Mhz
112
- BIOS Version: Google Google, 6/29/2022
113
- Windows Directory: C:\\Windows
114
- System Directory: C:\\Windows\\system32
115
- Boot Device: \\Device\\HarddiskVolume2
116
- System Locale: en-us;English (United States)
117
- Input Locale: en-us;English (United States)
118
- Time Zone: (UTC-08:00) Pacific Time (US & Canada)
119
- Total Physical Memory: 32,764 MB
120
- Available Physical Memory: 17,852 MB
121
- Virtual Memory: Max Size: 33,788 MB
122
- Virtual Memory: Available: 18,063 MB
123
- Virtual Memory: In Use: 15,725 MB
124
- Page File Location(s): C:\\pagefile.sys
125
- Domain: ad.corp.google.com
126
- Logon Server: \\CBF-DC-8
127
- Hotfix(s): 7 Hotfix(s) Installed.
128
- [01]: KB5013624
129
- [02]: KB5003791
130
- [03]: KB5012170
131
- [04]: KB5016616
132
- [05]: KB5014032
133
- [06]: KB5014671
134
- [07]: KB5015895
135
- Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.
136
- ''' ;
18
+ @override
19
+ final String name;
20
+ }
137
21
138
22
/// The expected validation result object for
139
23
/// a passing windows version test
@@ -143,14 +27,6 @@ const ValidationResult validWindows10ValidationResult = ValidationResult(
143
27
statusInfo: 'Installed version of Windows is version 10 or higher' ,
144
28
);
145
29
146
- /// The expected validation result object for
147
- /// a failing exit code (!= 0)
148
- const ValidationResult failedValidationResult = ValidationResult (
149
- ValidationType .missing,
150
- < ValidationMessage > [],
151
- statusInfo: 'Exit status from running `systeminfo` was unsuccessful' ,
152
- );
153
-
154
30
/// The expected validation result object for
155
31
/// a passing windows version test
156
32
const ValidationResult invalidWindowsValidationResult = ValidationResult (
@@ -159,28 +35,12 @@ const ValidationResult invalidWindowsValidationResult = ValidationResult(
159
35
statusInfo: 'Unable to confirm if installed Windows version is 10 or greater' ,
160
36
);
161
37
162
- /// Expected return from a nonzero exitcode when
163
- /// running systeminfo
164
- const ValidationResult invalidExitCodeValidationResult = ValidationResult (
165
- ValidationType .missing,
166
- < ValidationMessage > [],
167
- statusInfo: 'Exit status from running `systeminfo` was unsuccessful' ,
168
- );
169
-
170
38
void main () {
171
39
testWithoutContext ('Successfully running windows version check on windows 10' ,
172
40
() async {
173
41
final WindowsVersionValidator windowsVersionValidator =
174
42
WindowsVersionValidator (
175
- processManager: FakeProcessManager .list (
176
- < FakeCommand > [
177
- const FakeCommand (
178
- command: < String > ['systeminfo' ],
179
- stdout: validWindows10StdOut,
180
- ),
181
- ],
182
- ),
183
- );
43
+ operatingSystemUtils: FakeValidOperatingSystemUtils ());
184
44
185
45
final ValidationResult result = await windowsVersionValidator.validate ();
186
46
@@ -191,95 +51,31 @@ void main() {
191
51
});
192
52
193
53
testWithoutContext (
194
- 'Successfully running windows version check on windows 11 CN' ,
195
- () async {
196
- final WindowsVersionValidator windowsVersionValidator =
197
- WindowsVersionValidator (
198
- processManager: FakeProcessManager .list (
199
- < FakeCommand > [
200
- const FakeCommand (
201
- command: < String > ['systeminfo' ],
202
- stdout: validWindows11CnStdOut,
203
- ),
204
- ],
205
- ),
206
- );
207
-
208
- final ValidationResult result = await windowsVersionValidator.validate ();
209
-
210
- expect (
211
- result.type,
212
- validWindows10ValidationResult.type,
213
- reason: 'The ValidationResult type should be the same (installed)' ,
214
- );
215
- expect (
216
- result.statusInfo,
217
- validWindows10ValidationResult.statusInfo,
218
- reason: 'The ValidationResult statusInfo messages should be the same' ,
219
- );
220
- },
221
- );
222
-
223
- testWithoutContext ('Failing to invoke the `systeminfo` command' , () async {
54
+ 'Successfully running windows version check on windows 10 for BR' ,
55
+ () async {
224
56
final WindowsVersionValidator windowsVersionValidator =
225
57
WindowsVersionValidator (
226
- processManager: FakeProcessManager .list (
227
- < FakeCommand > [
228
- const FakeCommand (
229
- command: < String > ['systeminfo' ],
230
- stdout: validWindows10StdOut,
231
- exitCode: 1 ,
232
- ),
233
- ],
234
- ),
235
- );
58
+ operatingSystemUtils: FakeValidOperatingSystemUtils (
59
+ 'Microsoft Windows [versão 10.0.22621.1105]' ));
236
60
237
61
final ValidationResult result = await windowsVersionValidator.validate ();
238
62
239
- expect (result.type, failedValidationResult .type,
240
- reason: 'The ValidationResult type should be the same (missing )' );
241
- expect (result.statusInfo, failedValidationResult .statusInfo,
63
+ expect (result.type, validWindows10ValidationResult .type,
64
+ reason: 'The ValidationResult type should be the same (installed )' );
65
+ expect (result.statusInfo, validWindows10ValidationResult .statusInfo,
242
66
reason: 'The ValidationResult statusInfo messages should be the same' );
243
67
});
244
68
245
69
testWithoutContext ('Identifying a windows version before 10' , () async {
246
70
final WindowsVersionValidator windowsVersionValidator =
247
71
WindowsVersionValidator (
248
- processManager: FakeProcessManager .list (
249
- < FakeCommand > [
250
- const FakeCommand (
251
- command: < String > ['systeminfo' ],
252
- stdout: invalidWindowsStdOut,
253
- ),
254
- ],
255
- ),
256
- );
72
+ operatingSystemUtils: FakeValidOperatingSystemUtils (
73
+ 'Microsoft Windows [Version 8.0.22621.1105]' ));
257
74
258
75
final ValidationResult result = await windowsVersionValidator.validate ();
259
76
260
77
expect (result.type, invalidWindowsValidationResult.type,
261
78
reason: 'The ValidationResult type should be the same (missing)' );
262
- expect (result.statusInfo, invalidWindowsValidationResult.statusInfo,
263
- reason: 'The ValidationResult statusInfo messages should be the same' );
264
- });
265
-
266
- testWithoutContext (
267
- 'Running into an nonzero exit code from systeminfo command' , () async {
268
- final WindowsVersionValidator windowsVersionValidator =
269
- WindowsVersionValidator (
270
- processManager: FakeProcessManager .list (
271
- < FakeCommand > [
272
- const FakeCommand (command: < String > ['systeminfo' ], exitCode: 1 ),
273
- ],
274
- ),
275
- );
276
-
277
- final ValidationResult result = await windowsVersionValidator.validate ();
278
-
279
- expect (result.type, invalidExitCodeValidationResult.type,
280
- reason: 'The ValidationResult type should be the same (missing)' );
281
- expect (result.statusInfo, invalidExitCodeValidationResult.statusInfo,
282
- reason: 'The ValidationResult statusInfo messages should be the same' );
283
79
});
284
80
285
81
testWithoutContext ('Unit testing on a regex pattern validator' , () async {
@@ -300,10 +96,7 @@ OS 版本: 10.0.22621 暂缺 Build 22621
300
96
);
301
97
final Iterable <RegExpMatch > matches = regex.allMatches (testStr);
302
98
303
- expect (
304
- matches.length,
305
- 3 ,
306
- reason: 'There should be only two matches for the pattern provided' ,
307
- );
99
+ expect (matches.length, 5 ,
100
+ reason: 'There should be only 5 matches for the pattern provided' );
308
101
});
309
102
}
0 commit comments