@@ -4,7 +4,9 @@ import 'package:config_props_extractor/constants/constants.dart';
44import 'package:config_props_extractor/exceptions/exceptions.dart' ;
55import 'package:config_props_extractor/services/repo_service.dart' ;
66import 'package:config_props_extractor/services/shell_service.dart' ;
7+ import 'package:config_props_extractor/utils/string_utils.dart' ;
78import 'package:mocktail/mocktail.dart' ;
9+ import 'package:process_run/process_run.dart' ;
810import 'package:test/test.dart' ;
911
1012import '../helpers/mocks.dart' ;
@@ -50,9 +52,18 @@ void main() {
5052 );
5153 when (() => mockAppConfig.gitForceRemote).thenReturn (gitForceRemote);
5254 when (() => mockAppConfig.gitSSLEnabled).thenReturn (true );
53- when (() => mockShellService.runScript (any () )).thenAnswer (
55+ when (() => mockShellService.runScript (GIT_BRANCH_SHOW_CURRENT )).thenAnswer (
5456 (_) async => [ProcessResult (pid, exitCode, branch, stderr)],
5557 );
58+ when (() => mockShellService.runScript (GIT_CHECKOUT .format ([branch]))).thenAnswer (
59+ (_) async => [],
60+ );
61+ when (() => mockShellService.runScript (GIT_REMOTE_HARD_RESET .format ([branch, "" ]))).thenAnswer (
62+ (_) async => [],
63+ );
64+ when (() => mockShellService.runScript (GIT_TOP_LEVEL_PATH )).thenAnswer (
65+ (_) async => [ProcessResult (pid, exitCode, path, stderr)],
66+ );
5667
5768 // act
5869 await repoService.setup ();
@@ -70,7 +81,7 @@ void main() {
7081 () async => await testSetup (
7182 isBranchDefined: true ,
7283 gitForceRemote: true ,
73- runScriptTimes: 1 ,
84+ runScriptTimes: 2 ,
7485 ),
7586 );
7687
@@ -79,7 +90,7 @@ void main() {
7990 () async => testSetup (
8091 isBranchDefined: true ,
8192 gitForceRemote: true ,
82- runScriptTimes: 1 ,
93+ runScriptTimes: 2 ,
8394 ),
8495 );
8596
@@ -88,7 +99,7 @@ void main() {
8899 () async => testSetup (
89100 isBranchDefined: false ,
90101 gitForceRemote: false ,
91- runScriptTimes: 2 ,
102+ runScriptTimes: 3 ,
92103 ),
93104 );
94105
@@ -123,6 +134,36 @@ void main() {
123134 throwsA (isA <ExecutableNotFoundInPathException >()),
124135 );
125136 });
137+
138+
139+ test ("The path is invalid git repository" , () {
140+ // arrange
141+ when (() => mockAppConfig.gitRepoPath).thenReturn ("/path/to/sub/folder" );
142+ when (() => mockShellService.runScript (GIT_TOP_LEVEL_PATH )).thenAnswer (
143+ (_) async => [ProcessResult (pid, exitCode, "/path/to/sub" , stderr)],
144+ );
145+
146+ expect (
147+ // act
148+ () => repoService.setup (),
149+ // assert
150+ throwsA (isA <IncorrectTopLevelGitPathException >()),
151+ );
152+ });
153+
154+ test ("The path is not in the top-level of the git repository" , () {
155+ // arrange
156+ when (() => mockAppConfig.gitRepoPath).thenReturn ("/path/to/folder" );
157+ when (() => mockShellService.runScript (GIT_TOP_LEVEL_PATH ))
158+ .thenAnswer ((_) async => throw ShellException ("exception" , null ));
159+
160+ expect (
161+ // act
162+ () => repoService.setup (),
163+ // assert
164+ throwsA (isA <InvalidValidGitPathException >()),
165+ );
166+ });
126167 });
127168
128169 test (
0 commit comments