Unverified Commit 2adb1fc0 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Fix environment leakage in doctor_test (#54478)

parent d081364d
...@@ -365,6 +365,16 @@ void main() { ...@@ -365,6 +365,16 @@ void main() {
}); });
group('doctor with fake validators', () { group('doctor with fake validators', () {
MockArtifacts mockArtifacts;
const String genSnapshotPath = '/path/to/gen_snapshot';
FileSystem memoryFileSystem;
setUp(() {
memoryFileSystem = MemoryFileSystem.test();
mockArtifacts = MockArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.genSnapshot)).thenReturn(genSnapshotPath);
});
testUsingContext('validate non-verbose output format for run without issues', () async { testUsingContext('validate non-verbose output format for run without issues', () async {
expect(await FakeQuietDoctor().diagnose(verbose: false), isTrue); expect(await FakeQuietDoctor().diagnose(verbose: false), isTrue);
expect(testLogger.statusText, equals( expect(testLogger.statusText, equals(
...@@ -507,8 +517,9 @@ void main() { ...@@ -507,8 +517,9 @@ void main() {
}, overrides: noColorTerminalOverride); }, overrides: noColorTerminalOverride);
testUsingContext('gen_snapshot does not work', () async { testUsingContext('gen_snapshot does not work', () async {
memoryFileSystem.file(genSnapshotPath).createSync(recursive: true);
when(mockProcessManager.runSync( when(mockProcessManager.runSync(
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)], <String>[genSnapshotPath],
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).thenReturn(ProcessResult(101, 1, '', '')); )).thenReturn(ProcessResult(101, 1, '', ''));
...@@ -524,6 +535,8 @@ void main() { ...@@ -524,6 +535,8 @@ void main() {
} }
} }
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
FileSystem: () => memoryFileSystem,
OutputPreferences: () => OutputPreferences(wrapText: false), OutputPreferences: () => OutputPreferences(wrapText: false),
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Platform: _kNoColorOutputPlatform, Platform: _kNoColorOutputPlatform,
...@@ -535,11 +548,13 @@ void main() { ...@@ -535,11 +548,13 @@ void main() {
// fail if the gen_snapshot binary is not present. // fail if the gen_snapshot binary is not present.
expect(testLogger.statusText, contains('No issues found!')); expect(testLogger.statusText, contains('No issues found!'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
FileSystem: () => MemoryFileSystem(), FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('version checking does not work', () async { testUsingContext('version checking does not work', () async {
memoryFileSystem.file(genSnapshotPath).createSync(recursive: true);
final VersionCheckError versionCheckError = VersionCheckError('version error'); final VersionCheckError versionCheckError = VersionCheckError('version error');
when(mockFlutterVersion.channel).thenReturn('unknown'); when(mockFlutterVersion.channel).thenReturn('unknown');
...@@ -547,7 +562,7 @@ void main() { ...@@ -547,7 +562,7 @@ void main() {
when(mockFlutterVersion.frameworkDate).thenThrow(versionCheckError); when(mockFlutterVersion.frameworkDate).thenThrow(versionCheckError);
when(mockProcessManager.runSync( when(mockProcessManager.runSync(
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)], <String>[genSnapshotPath],
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).thenReturn(ProcessResult(101, 255, '', '')); )).thenReturn(ProcessResult(101, 255, '', ''));
...@@ -561,6 +576,8 @@ void main() { ...@@ -561,6 +576,8 @@ void main() {
'! Doctor found issues in 1 category.\n' '! Doctor found issues in 1 category.\n'
)); ));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
FileSystem: () => memoryFileSystem,
OutputPreferences: () => OutputPreferences(wrapText: false), OutputPreferences: () => OutputPreferences(wrapText: false),
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Platform: _kNoColorOutputPlatform, Platform: _kNoColorOutputPlatform,
...@@ -736,6 +753,7 @@ void main() { ...@@ -736,6 +753,7 @@ void main() {
contains(isA<WebWorkflow>())); contains(isA<WebWorkflow>()));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true), FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
}); });
...@@ -1122,3 +1140,4 @@ class VsCodeValidatorTestTargets extends VsCodeValidator { ...@@ -1122,3 +1140,4 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
} }
class MockProcessManager extends Mock implements ProcessManager {} class MockProcessManager extends Mock implements ProcessManager {}
class MockArtifacts extends Mock implements Artifacts {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment