mirror of
https://github.com/flutter/packages.git
synced 2025-08-23 10:25:45 +08:00

Consolidates the code to find all changed file paths into the `PackageLoopingCommand` class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively *don't* affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes). A side effect of this change is that tests of almost all commands now need a mock `GitDir` instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup: - Creating a memory file system - Populating it with a packages directory - Creating a RecordingProcessRunner to mock out process calls - Creating a mock GitDir that forwards to a RecordingProcessRunner into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general. Prep for https://github.com/flutter/flutter/issues/136394
178 lines
5.4 KiB
Dart
178 lines
5.4 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:args/command_runner.dart';
|
|
import 'package:file/file.dart';
|
|
import 'package:flutter_plugin_tools/src/common/core.dart';
|
|
import 'package:flutter_plugin_tools/src/dependabot_check_command.dart';
|
|
import 'package:git/git.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'util.dart';
|
|
|
|
void main() {
|
|
late CommandRunner<void> runner;
|
|
late Directory root;
|
|
late Directory packagesDir;
|
|
|
|
setUp(() {
|
|
final GitDir gitDir;
|
|
(:packagesDir, processRunner: _, gitProcessRunner: _, :gitDir) =
|
|
configureBaseCommandMocks();
|
|
root = packagesDir.parent;
|
|
|
|
final DependabotCheckCommand command = DependabotCheckCommand(
|
|
packagesDir,
|
|
gitDir: gitDir,
|
|
);
|
|
runner = CommandRunner<void>(
|
|
'dependabot_test', 'Test for $DependabotCheckCommand');
|
|
runner.addCommand(command);
|
|
});
|
|
|
|
void setDependabotCoverage({
|
|
Iterable<String> gradleDirs = const <String>[],
|
|
bool useDirectoriesKey = false,
|
|
}) {
|
|
final String gradleEntries;
|
|
if (useDirectoriesKey) {
|
|
gradleEntries = '''
|
|
- package-ecosystem: "gradle"
|
|
directories:
|
|
${gradleDirs.map((String directory) => ' - /$directory').join('\n')}
|
|
schedule:
|
|
interval: "daily"
|
|
''';
|
|
} else {
|
|
gradleEntries = gradleDirs.map((String directory) => '''
|
|
- package-ecosystem: "gradle"
|
|
directory: "/$directory"
|
|
schedule:
|
|
interval: "daily"
|
|
''').join('\n');
|
|
}
|
|
final File configFile =
|
|
root.childDirectory('.github').childFile('dependabot.yml');
|
|
configFile.createSync(recursive: true);
|
|
configFile.writeAsStringSync('''
|
|
version: 2
|
|
updates:
|
|
$gradleEntries
|
|
''');
|
|
}
|
|
|
|
test('skips with no supported ecosystems', () async {
|
|
setDependabotCoverage();
|
|
createFakePackage('a_package', packagesDir);
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['dependabot-check']);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('SKIPPING: No supported package ecosystems'),
|
|
]));
|
|
});
|
|
|
|
test('fails for app missing Gradle coverage', () async {
|
|
setDependabotCoverage();
|
|
final RepositoryPackage package =
|
|
createFakePackage('a_package', packagesDir);
|
|
package.directory
|
|
.childDirectory('example')
|
|
.childDirectory('android')
|
|
.childDirectory('app')
|
|
.createSync(recursive: true);
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['dependabot-check'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('Missing Gradle coverage.'),
|
|
contains(
|
|
'Add a "gradle" entry to .github/dependabot.yml for /packages/a_package/example/android/app'),
|
|
contains('a_package/example:\n'
|
|
' Missing Gradle coverage')
|
|
]));
|
|
});
|
|
|
|
test('fails for plugin missing Gradle coverage', () async {
|
|
setDependabotCoverage();
|
|
final RepositoryPackage plugin = createFakePlugin('a_plugin', packagesDir);
|
|
plugin.directory.childDirectory('android').createSync(recursive: true);
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['dependabot-check'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('Missing Gradle coverage.'),
|
|
contains(
|
|
'Add a "gradle" entry to .github/dependabot.yml for /packages/a_plugin/android'),
|
|
contains('a_plugin:\n'
|
|
' Missing Gradle coverage')
|
|
]));
|
|
});
|
|
|
|
test('passes for correct Gradle coverage with single directory', () async {
|
|
setDependabotCoverage(gradleDirs: <String>[
|
|
'packages/a_plugin/android',
|
|
'packages/a_plugin/example/android/app',
|
|
]);
|
|
final RepositoryPackage plugin = createFakePlugin('a_plugin', packagesDir);
|
|
// Test the plugin.
|
|
plugin.directory.childDirectory('android').createSync(recursive: true);
|
|
// And its example app.
|
|
plugin.directory
|
|
.childDirectory('example')
|
|
.childDirectory('android')
|
|
.childDirectory('app')
|
|
.createSync(recursive: true);
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['dependabot-check']);
|
|
|
|
expect(output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 2 package(s)')]));
|
|
});
|
|
|
|
test('passes for correct Gradle coverage with multiple directories',
|
|
() async {
|
|
setDependabotCoverage(
|
|
gradleDirs: <String>[
|
|
'packages/a_plugin/android',
|
|
'packages/a_plugin/example/android/app',
|
|
],
|
|
useDirectoriesKey: true,
|
|
);
|
|
final RepositoryPackage plugin = createFakePlugin('a_plugin', packagesDir);
|
|
// Test the plugin.
|
|
plugin.directory.childDirectory('android').createSync(recursive: true);
|
|
// And its example app.
|
|
plugin.directory
|
|
.childDirectory('example')
|
|
.childDirectory('android')
|
|
.childDirectory('app')
|
|
.createSync(recursive: true);
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['dependabot-check']);
|
|
|
|
expect(output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 2 package(s)')]));
|
|
});
|
|
}
|