Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
65549d77
Unverified
Commit
65549d77
authored
Jun 11, 2021
by
Jonah Williams
Committed by
GitHub
Jun 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] reduce mocking in error handling io (#84443)
parent
80668d20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
37 deletions
+64
-37
error_handling_io_test.dart
...tools/test/general.shard/base/error_handling_io_test.dart
+64
-37
No files found.
packages/flutter_tools/test/general.shard/base/error_handling_io_test.dart
View file @
65549d77
...
...
@@ -39,23 +39,6 @@ final Platform macOSPlatform = FakePlatform(
environment:
<
String
,
String
>{}
);
void
setupReadMocks
(
{
FileSystem
mockFileSystem
,
ErrorHandlingFileSystem
fs
,
int
errorCode
,
})
{
final
MockFile
mockFile
=
MockFile
();
final
MockDirectory
mockParentDirectory
=
MockDirectory
();
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
when
(
mockFile
.
path
).
thenReturn
(
'parent/file'
);
when
(
mockFile
.
parent
).
thenReturn
(
mockParentDirectory
);
when
(
mockParentDirectory
.
path
).
thenReturn
(
'parent'
);
when
(
mockFileSystem
.
currentDirectory
).
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
when
(
mockFile
.
readAsStringSync
(
encoding:
anyNamed
(
'encoding'
),
)).
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
}
void
setupDirectoryMocks
(
{
FileSystem
mockFileSystem
,
ErrorHandlingFileSystem
fs
,
...
...
@@ -367,19 +350,31 @@ void main() {
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'When reading from a file or directory without permission'
,
()
{
setupReadMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kUserPermissionDenied
,
testWithoutContext
(
'When reading from a file without permission'
,
()
{
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
MemoryFileSystem
.
test
(
opHandle:
exceptionHandler
.
opHandle
),
platform:
windowsPlatform
,
);
final
File
file
=
fileSystem
.
file
(
'file'
);
final
File
file
=
fs
.
file
(
'file'
);
exceptionHandler
.
addError
(
file
,
FileSystemOp
.
read
,
FileSystemException
(
''
,
file
.
path
,
const
OSError
(
''
,
kUserPermissionDenied
)),
);
const
String
expectedMessage
=
'Flutter failed to read a file at'
;
expect
(()
=>
file
.
readAsStringSync
(),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
fs
.
currentDirectory
,
});
testWithoutContext
(
'When reading from a file or directory without permission'
,
()
{
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
ThrowsOnCurrentDirectoryFileSystem
()..
errorCode
=
kUserPermissionDenied
,
platform:
windowsPlatform
,
);
expect
(()
=>
fileSystem
.
currentDirectory
,
throwsToolExit
(
message:
'The flutter tool cannot access the file or directory'
));
});
});
...
...
@@ -563,16 +558,29 @@ void main() {
});
testWithoutContext
(
'When the current working directory disappears'
,
()
async
{
setupReadMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kSystemCannotFindFile
,
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
ThrowsOnCurrentDirectoryFileSystem
()..
errorCode
=
kSystemCannotFindFile
,
platform:
linuxPlatform
,
);
expect
(()
=>
fs
.
currentDirectory
,
throwsToolExit
(
message:
'Unable to read current working directory'
));
expect
(()
=>
fileSystem
.
currentDirectory
,
throwsToolExit
(
message:
'Unable to read current working directory'
));
});
testWithoutContext
(
'Rethrows os error
$kSystemCannotFindFile
'
,
()
{
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
MemoryFileSystem
.
test
(
opHandle:
exceptionHandler
.
opHandle
),
platform:
linuxPlatform
,
);
final
File
file
=
fileSystem
.
file
(
'file'
);
exceptionHandler
.
addError
(
file
,
FileSystemOp
.
read
,
FileSystemException
(
''
,
file
.
path
,
const
OSError
(
''
,
kSystemCannotFindFile
)),
);
// Error is not caught by other operations.
expect
(()
=>
f
s
.
file
(
'foo'
).
readAsStringSync
(),
throwsFileSystemException
(
kSystemCannotFindFile
));
expect
(()
=>
f
ileSystem
.
file
(
'foo'
).
readAsStringSync
(),
throwsFileSystemException
(
kSystemCannotFindFile
));
});
});
...
...
@@ -753,19 +761,31 @@ void main() {
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'When reading from a file or directory without permission'
,
()
{
setupReadMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
eacces
,
testWithoutContext
(
'When reading from a file without permission'
,
()
{
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
MemoryFileSystem
.
test
(
opHandle:
exceptionHandler
.
opHandle
),
platform:
linuxPlatform
,
);
final
File
file
=
fileSystem
.
file
(
'file'
);
final
File
file
=
fs
.
file
(
'file'
);
exceptionHandler
.
addError
(
file
,
FileSystemOp
.
read
,
FileSystemException
(
''
,
file
.
path
,
const
OSError
(
''
,
eacces
)),
);
const
String
expectedMessage
=
'Flutter failed to read a file at'
;
expect
(()
=>
file
.
readAsStringSync
(),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
fs
.
currentDirectory
,
});
testWithoutContext
(
'When reading from current directory without permission'
,
()
{
final
ErrorHandlingFileSystem
fileSystem
=
ErrorHandlingFileSystem
(
delegate:
ThrowsOnCurrentDirectoryFileSystem
()..
errorCode
=
eacces
,
platform:
linuxPlatform
,
);
expect
(()
=>
fileSystem
.
currentDirectory
,
throwsToolExit
(
message:
'The flutter tool cannot access the file or directory'
));
});
});
...
...
@@ -1250,3 +1270,10 @@ class ThrowingFakeProcessManager extends Fake implements ProcessManager {
throw
_exception
;
}
}
class
ThrowsOnCurrentDirectoryFileSystem
extends
Fake
implements
FileSystem
{
int
errorCode
;
@override
Directory
get
currentDirectory
=>
throw
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment