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
e11a1a83
Unverified
Commit
e11a1a83
authored
Apr 13, 2021
by
Jenn Magder
Committed by
GitHub
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove mocks from fucshia_pm_test, reduce createMockProcess usage (#80321)
parent
7e24faf0
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
117 deletions
+160
-117
build_apk_test.dart
...r_tools/test/commands.shard/permeable/build_apk_test.dart
+19
-1
pub_get_test.dart
...s/flutter_tools/test/general.shard/dart/pub_get_test.dart
+114
-66
fuchsia_pm_test.dart
...ter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart
+26
-31
fake_process_manager.dart
packages/flutter_tools/test/src/fake_process_manager.dart
+1
-0
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+0
-19
No files found.
packages/flutter_tools/test/commands.shard/permeable/build_apk_test.dart
View file @
e11a1a83
...
...
@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/build_apk.dart'
;
import
'package:flutter_tools/src/convert.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
...
...
@@ -22,7 +23,6 @@ import 'package:process/process.dart';
import
'../../src/android_common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
hide
MockAndroidSdk
;
import
'../../src/test_flutter_command_runner.dart'
;
void
main
(
)
{
...
...
@@ -537,3 +537,21 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
/// Creates a mock process that returns with the given [exitCode], [stdout] and [stderr].
Process
createMockProcess
(
{
int
exitCode
=
0
,
String
stdout
=
''
,
String
stderr
=
''
})
{
final
Stream
<
List
<
int
>>
stdoutStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stdout
),
]);
final
Stream
<
List
<
int
>>
stderrStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stderr
),
]);
final
Process
process
=
_MockBasicProcess
();
when
(
process
.
stdout
).
thenAnswer
((
_
)
=>
stdoutStream
);
when
(
process
.
stderr
).
thenAnswer
((
_
)
=>
stderrStream
);
when
(
process
.
exitCode
).
thenAnswer
((
_
)
=>
Future
<
int
>.
value
(
exitCode
));
return
process
;
}
class
_MockBasicProcess
extends
Mock
implements
Process
{}
packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
View file @
e11a1a83
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart
View file @
e11a1a83
...
...
@@ -6,71 +6,66 @@
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/fuchsia/fuchsia_pm.dart'
;
import
'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/
mocks
.dart'
;
import
'../../src/
fake_process_manager
.dart'
;
void
main
(
)
{
group
(
'FuchsiaPM'
,
()
{
File
pm
;
MockProcessManager
mock
ProcessManager
;
MockFuchsiaArtifacts
mock
FuchsiaArtifacts
;
FakeProcessManager
fake
ProcessManager
;
FakeFuchsiaArtifacts
fake
FuchsiaArtifacts
;
setUp
(()
{
pm
=
MemoryFileSystem
.
test
().
file
(
'pm'
);
mockFuchsiaArtifacts
=
MockFuchsiaArtifacts
();
when
(
mockFuchsiaArtifacts
.
pm
).
thenReturn
(
pm
);
mockProcessManager
=
MockProcessManager
();
fakeFuchsiaArtifacts
=
FakeFuchsiaArtifacts
(
pm
);
fakeProcessManager
=
FakeProcessManager
.
empty
();
});
testUsingContext
(
'serve - IPv4 address'
,
()
async
{
when
(
mockProcessManager
.
start
(
any
)).
thenAnswer
((
_
)
{
return
Future
<
Process
>.
value
(
createMockProcess
());
});
await
FuchsiaPM
().
serve
(
'<repo>'
,
'127.0.0.1'
,
43819
);
verify
(
mockProcessManager
.
start
(<
String
>[
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'pm'
,
'serve'
,
'-repo'
,
'<repo>'
,
'-l'
,
'127.0.0.1:43819'
,
])).
called
(
1
);
]));
await
FuchsiaPM
().
serve
(
'<repo>'
,
'127.0.0.1'
,
43819
);
expect
(
fakeProcessManager
,
hasNoRemainingExpectations
);
},
overrides:
<
Type
,
Generator
>{
FuchsiaArtifacts:
()
=>
mock
FuchsiaArtifacts
,
ProcessManager:
()
=>
mock
ProcessManager
,
FuchsiaArtifacts:
()
=>
fake
FuchsiaArtifacts
,
ProcessManager:
()
=>
fake
ProcessManager
,
});
testUsingContext
(
'serve - IPv6 address'
,
()
async
{
when
(
mockProcessManager
.
start
(
any
)).
thenAnswer
((
_
)
{
return
Future
<
Process
>.
value
(
createMockProcess
());
});
await
FuchsiaPM
().
serve
(
'<repo>'
,
'fe80::ec4:7aff:fecc:ea8f%eno2'
,
43819
);
verify
(
mockProcessManager
.
start
(<
String
>[
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'pm'
,
'serve'
,
'-repo'
,
'<repo>'
,
'-l'
,
'[fe80::ec4:7aff:fecc:ea8f%eno2]:43819'
,
])).
called
(
1
);
]));
await
FuchsiaPM
().
serve
(
'<repo>'
,
'fe80::ec4:7aff:fecc:ea8f%eno2'
,
43819
);
expect
(
fakeProcessManager
,
hasNoRemainingExpectations
);
},
overrides:
<
Type
,
Generator
>{
FuchsiaArtifacts:
()
=>
mock
FuchsiaArtifacts
,
ProcessManager:
()
=>
mock
ProcessManager
,
FuchsiaArtifacts:
()
=>
fake
FuchsiaArtifacts
,
ProcessManager:
()
=>
fake
ProcessManager
,
});
});
}
class
MockFuchsiaArtifacts
extends
Mock
implements
FuchsiaArtifacts
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
FakeFuchsiaArtifacts
extends
Fake
implements
FuchsiaArtifacts
{
FakeFuchsiaArtifacts
(
this
.
pm
);
@override
final
File
pm
;
}
packages/flutter_tools/test/src/fake_process_manager.dart
View file @
e11a1a83
...
...
@@ -191,6 +191,7 @@ abstract class FakeProcessManager implements ProcessManager {
/// last command and verify its execution is successful, to ensure that all
/// the specified commands are actually called.
factory
FakeProcessManager
.
list
(
List
<
FakeCommand
>
commands
)
=
_SequenceProcessManager
;
factory
FakeProcessManager
.
empty
()
=>
_SequenceProcessManager
(<
FakeCommand
>[]);
FakeProcessManager
.
_
();
...
...
packages/flutter_tools/test/src/mocks.dart
View file @
e11a1a83
...
...
@@ -5,7 +5,6 @@
// @dart = 2.8
import
'dart:async'
;
import
'dart:convert'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/android/android_sdk.dart'
show
AndroidSdk
;
...
...
@@ -156,24 +155,6 @@ _ProcessFactory flakyProcessFactory({
};
}
/// Creates a mock process that returns with the given [exitCode], [stdout] and [stderr].
Process
createMockProcess
(
{
int
exitCode
=
0
,
String
stdout
=
''
,
String
stderr
=
''
})
{
final
Stream
<
List
<
int
>>
stdoutStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stdout
),
]);
final
Stream
<
List
<
int
>>
stderrStream
=
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
stderr
),
]);
final
Process
process
=
_MockBasicProcess
();
when
(
process
.
stdout
).
thenAnswer
((
_
)
=>
stdoutStream
);
when
(
process
.
stderr
).
thenAnswer
((
_
)
=>
stderrStream
);
when
(
process
.
exitCode
).
thenAnswer
((
_
)
=>
Future
<
int
>.
value
(
exitCode
));
return
process
;
}
class
_MockBasicProcess
extends
Mock
implements
Process
{}
class
MockAndroidDevice
extends
Mock
implements
AndroidDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
android_arm
;
...
...
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