[flutter_plugin_tools] Improve process mocking (#4254)

The mock process runner used in most of the tests had poor handling of
stdout/stderr:
- By default it would return the `List<int>` output from the mock
  process, which was never correct since the parent process runner
  interface always sets encodings, thus the `dynamic` should always be
  of type `String`
- The process for setting output on a `MockProcess` was awkward, since
  it was based on a `Stream<Lint<int>>`, even though in every case what
  we actually want to do is just set the full output to a string.
- A hack was at some point added (presumably due to the above issues)
  to bypass that flow at the process runner level, and instead return a
  `String` set there. That meant there were two ways of setting output
  (one of which that only worked for one of the ways of running
  processes)
  - That hack wasn't updated when the ability to return multiple mock
    processes instead of a single global mock process was added, so the
    API was even more confusing, and there was no way to set different
    output for different processes.

This changes the test APIs so that:
- `MockProcess` takes stdout and stderr as strings, and internally
  manages converting them to a `Stream<List<int>>`.
- `RecordingProcessRunner` correctly decodes and returns the output
  streams when constructing a process result.

It also removes the resultStdout and resultStderr hacks, as well as the
legacy `processToReturn` API, and converts all uses to the new
structure, which is both simpler to use, and clearly associates output
with specific processes.
This commit is contained in:
stuartmorgan
2021-08-24 14:42:21 -04:00
committed by GitHub
parent 5bbc1791cc
commit 74cf0287f9
16 changed files with 199 additions and 193 deletions

View File

@ -40,7 +40,7 @@ void main() {
test('fails if gcloud auth fails', () async {
processRunner.mockProcessesForExecutable['gcloud'] = <Process>[
MockProcess.failing()
MockProcess(exitCode: 1)
];
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
'example/integration_test/foo_test.dart',
@ -64,8 +64,8 @@ void main() {
test('retries gcloud set', () async {
processRunner.mockProcessesForExecutable['gcloud'] = <Process>[
MockProcess.succeeding(), // auth
MockProcess.failing(), // config
MockProcess(), // auth
MockProcess(exitCode: 1), // config
];
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
'example/integration_test/foo_test.dart',
@ -245,10 +245,10 @@ void main() {
]);
processRunner.mockProcessesForExecutable['gcloud'] = <Process>[
MockProcess.succeeding(), // auth
MockProcess.succeeding(), // config
MockProcess.failing(), // integration test #1
MockProcess.succeeding(), // integration test #2
MockProcess(), // auth
MockProcess(), // config
MockProcess(exitCode: 1), // integration test #1
MockProcess(), // integration test #2
];
Error? commandError;
@ -459,7 +459,7 @@ void main() {
]);
processRunner.mockProcessesForExecutable['flutter'] = <Process>[
MockProcess.failing() // flutter build
MockProcess(exitCode: 1) // flutter build
];
Error? commandError;
@ -496,7 +496,7 @@ void main() {
.childFile('gradlew')
.path;
processRunner.mockProcessesForExecutable[gradlewPath] = <Process>[
MockProcess.failing()
MockProcess(exitCode: 1)
];
Error? commandError;
@ -533,8 +533,8 @@ void main() {
.childFile('gradlew')
.path;
processRunner.mockProcessesForExecutable[gradlewPath] = <Process>[
MockProcess.succeeding(), // assembleAndroidTest
MockProcess.failing(), // assembleDebug
MockProcess(), // assembleAndroidTest
MockProcess(exitCode: 1), // assembleDebug
];
Error? commandError;