|
| 1 | +import 'package:mason/mason.dart'; |
| 2 | +import 'package:mocktail/mocktail.dart'; |
1 | 3 | import 'package:test/test.dart';
|
| 4 | +import 'package:universal_io/io.dart'; |
2 | 5 | import 'package:very_good_cli/src/cli/cli.dart';
|
3 | 6 |
|
| 7 | +class _TestProcess { |
| 8 | + Future<ProcessResult> run( |
| 9 | + String command, |
| 10 | + List<String> args, { |
| 11 | + bool runInShell = false, |
| 12 | + String? workingDirectory, |
| 13 | + }) { |
| 14 | + throw UnimplementedError(); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +class _MockProcess extends Mock implements _TestProcess {} |
| 19 | + |
| 20 | +class _MockProcessResult extends Mock implements ProcessResult {} |
| 21 | + |
4 | 22 | void main() {
|
5 | 23 | group('Git', () {
|
| 24 | + late ProcessResult processResult; |
| 25 | + late _TestProcess process; |
| 26 | + |
| 27 | + setUp(() { |
| 28 | + processResult = _MockProcessResult(); |
| 29 | + process = _MockProcess(); |
| 30 | + when(() => processResult.exitCode).thenReturn(ExitCode.success.code); |
| 31 | + when( |
| 32 | + () => process.run( |
| 33 | + any(), |
| 34 | + any(), |
| 35 | + runInShell: any(named: 'runInShell'), |
| 36 | + workingDirectory: any(named: 'workingDirectory'), |
| 37 | + ), |
| 38 | + ).thenAnswer((_) async => processResult); |
| 39 | + }); |
| 40 | + |
6 | 41 | group('reachable', () {
|
7 | 42 | test('completes for a reachable remote', () async {
|
8 |
| - await expectLater( |
9 |
| - Git.reachable( |
10 |
| - Uri.parse('https://github.com/verygoodopensource/very_good_cli'), |
11 |
| - ), |
12 |
| - completes, |
| 43 | + await ProcessOverrides.runZoned( |
| 44 | + () async { |
| 45 | + await expectLater( |
| 46 | + Git.reachable(Uri.parse('https://github.com/org/repo')), |
| 47 | + completes, |
| 48 | + ); |
| 49 | + }, |
| 50 | + runProcess: process.run, |
13 | 51 | );
|
14 | 52 | });
|
15 | 53 |
|
16 |
| - test('throws UnreachableGitDependency for an unreachable remote', |
| 54 | + test( |
| 55 | + 'throws UnreachableGitDependency ' |
| 56 | + 'for an unreachable remote', () async { |
| 57 | + when(() => processResult.exitCode).thenReturn(ExitCode.software.code); |
| 58 | + await ProcessOverrides.runZoned( |
17 | 59 | () async {
|
18 |
| - await expectLater( |
19 |
| - Git.reachable( |
20 |
| - Uri.parse('https://github.com/verygoodopensource/_very_good_cli'), |
21 |
| - ), |
22 |
| - throwsA(isA<UnreachableGitDependency>()), |
| 60 | + await expectLater( |
| 61 | + Git.reachable(Uri.parse('https://github.com/org/repo')), |
| 62 | + throwsA(isA<UnreachableGitDependency>()), |
| 63 | + ); |
| 64 | + }, |
| 65 | + runProcess: process.run, |
23 | 66 | );
|
24 | 67 | });
|
25 | 68 | });
|
26 | 69 |
|
27 | 70 | group('UnreachableGitDependency', () {
|
28 | 71 | test('has correct toString override', () {
|
29 |
| - final remote = |
30 |
| - Uri.parse('https://github.com/verygoodopensource/_very_good_cli'); |
| 72 | + final remote = Uri.parse('https://github.com/org/repo'); |
31 | 73 | final exception = UnreachableGitDependency(remote: remote);
|
32 | 74 | expect(
|
33 | 75 | exception.toString(),
|
|
0 commit comments