diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 9cd6203d5..eec6cd8ad 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -47,6 +47,10 @@ jobs: - test/commands/create/flutter_package/flutter_pkg_test.dart - test/commands/create/flutter_plugin/flutter_plugin_test.dart + # E2E tests for the `packages check licenses` command + - test/commands/packages/check/licenses/licenses_allowed_test.dart + - test/commands/packages/check/licenses/licenses_forbidden_test.dart + steps: - name: 📚 Git Checkout uses: actions/checkout@v4 diff --git a/e2e/test/commands/packages/check/licenses/licenses_allowed_test.dart b/e2e/test/commands/packages/check/licenses/licenses_allowed_test.dart new file mode 100644 index 000000000..ad8e13abb --- /dev/null +++ b/e2e/test/commands/packages/check/licenses/licenses_allowed_test.dart @@ -0,0 +1,60 @@ +import 'dart:io'; + +import 'package:mason/mason.dart'; +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; + +import '../../../../../helpers/helpers.dart'; + +/// Objectives: +/// +/// * Generate a new Dart project using (`dart create`) +/// * Add dependencies to `pubspec.yaml` with an MIT license +/// * Run `very_good packages check licenses --allowed="MIT"` and expect success +void main() { + test( + 'packages check licenses --allowed="MIT"', + timeout: const Timeout(Duration(minutes: 2)), + withRunner((commandRunner, logger, updater, logs) async { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); + + const projectName = 'my_dart_project'; + await expectSuccessfulProcessResult( + 'dart', + ['create', 'my_dart_project', '--no-pub'], + workingDirectory: tempDirectory.path, + ); + final projectPath = path.join(tempDirectory.path, projectName); + await expectSuccessfulProcessResult( + 'dart', + ['pub', 'add', 'formz'], + workingDirectory: projectPath, + ); + await expectSuccessfulProcessResult( + 'dart', + ['pub', 'get'], + workingDirectory: projectPath, + ); + + final relativeProjectPath = path.relative( + projectPath, + from: Directory.current.path, + ); + final resultAllowed = await commandRunner.run( + [ + 'packages', + 'check', + 'licenses', + '--allowed=MIT', + relativeProjectPath, + ], + ); + expect( + resultAllowed, + equals(ExitCode.success.code), + reason: 'Should succeed when allowed licenses are used', + ); + }), + ); +} diff --git a/e2e/test/commands/packages/check/licenses/licenses_forbidden_test.dart b/e2e/test/commands/packages/check/licenses/licenses_forbidden_test.dart new file mode 100644 index 000000000..2f4c79006 --- /dev/null +++ b/e2e/test/commands/packages/check/licenses/licenses_forbidden_test.dart @@ -0,0 +1,62 @@ +import 'dart:io'; + +import 'package:mason/mason.dart'; +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; + +import '../../../../../helpers/helpers.dart'; + +/// Objectives: +/// +/// * Generate a new Dart project using (`dart create`) +/// * Add dependencies to `pubspec.yaml` with an MIT license +/// * Run `very_good packages check licenses --forbidden="MIT"` and expect +/// failure +void main() { + test( + 'packages check licenses --forbidden="MIT"', + timeout: const Timeout(Duration(minutes: 2)), + withRunner((commandRunner, logger, updater, logs) async { + final tempDirectory = Directory.systemTemp.createTempSync(); + addTearDown(() => tempDirectory.deleteSync(recursive: true)); + + const projectName = 'my_dart_project'; + await expectSuccessfulProcessResult( + 'dart', + ['create', 'my_dart_project', '--no-pub'], + workingDirectory: tempDirectory.path, + ); + final projectPath = path.join(tempDirectory.path, projectName); + await expectSuccessfulProcessResult( + 'dart', + ['pub', 'add', 'formz'], + workingDirectory: projectPath, + ); + await expectSuccessfulProcessResult( + 'dart', + ['pub', 'get'], + workingDirectory: projectPath, + ); + + final relativeProjectPath = path.relative( + projectPath, + from: Directory.current.path, + ); + + final resultForbidden = await commandRunner.run( + [ + 'packages', + 'check', + 'licenses', + '--forbidden=MIT', + relativeProjectPath, + ], + ); + expect( + resultForbidden, + equals(ExitCode.config.code), + reason: 'Should fail when forbidden licenses are used', + ); + }), + ); +}