@@ -51,6 +51,9 @@ public async Task Go117ModDetector_GoCliIs1_11OrGreater_GoGraphIsExecutedAsync()
5151 {
5252 var goMod = string . Empty ;
5353
54+ this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
55+ . ReturnsAsync ( true ) ;
56+
5457 this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
5558 . ReturnsAsync ( new CommandLineExecutionResult
5659 {
@@ -85,6 +88,9 @@ public async Task Go117ModDetector_GoCliIs111OrLessThan1_11_GoGraphIsNotExecuted
8588 {
8689 var goMod = string . Empty ;
8790
91+ this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
92+ . ReturnsAsync ( true ) ;
93+
8894 this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
8995 . ReturnsAsync ( new CommandLineExecutionResult
9096 {
@@ -114,6 +120,9 @@ public async Task Go117ModDetector_GoModFileFound_GoModParserIsExecuted()
114120 var goModParserMock = new Mock < IGoParser > ( ) ;
115121 this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoMod , It . IsAny < ILogger > ( ) ) ) . Returns ( goModParserMock . Object ) ;
116122
123+ this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
124+ . ReturnsAsync ( true ) ;
125+
117126 this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
118127 . ReturnsAsync ( new CommandLineExecutionResult
119128 {
@@ -136,6 +145,9 @@ public async Task Go117ModDetector_GoSumFileFound_GoSumParserIsExecuted()
136145 var goSumParserMock = new Mock < IGoParser > ( ) ;
137146 this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoSum , It . IsAny < ILogger > ( ) ) ) . Returns ( goSumParserMock . Object ) ;
138147
148+ this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
149+ . ReturnsAsync ( true ) ;
150+
139151 this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
140152 . ReturnsAsync ( new CommandLineExecutionResult
141153 {
@@ -151,4 +163,25 @@ public async Task Go117ModDetector_GoSumFileFound_GoSumParserIsExecuted()
151163
152164 goSumParserMock . Verify ( parser => parser . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) , Times . Once ) ;
153165 }
166+
167+ [ TestMethod ]
168+ public async Task Go117ModDetector_ExecutingGoVersionFails_DetectorDoesNotFail ( )
169+ {
170+ var goModParserMock = new Mock < IGoParser > ( ) ;
171+ this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoMod , It . IsAny < ILogger > ( ) ) ) . Returns ( goModParserMock . Object ) ;
172+
173+ this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
174+ . ReturnsAsync ( true ) ;
175+
176+ this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
177+ . Throws ( new InvalidOperationException ( "Failed to execute go version" ) ) ;
178+
179+ var ( scanResult , componentRecorder ) = await this . DetectorTestUtility
180+ . WithFile ( "go.mod" , string . Empty )
181+ . ExecuteDetectorAsync ( ) ;
182+
183+ scanResult . ResultCode . Should ( ) . Be ( ProcessingResultCode . Success ) ;
184+
185+ goModParserMock . Verify ( parser => parser . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) , Times . Once ) ;
186+ }
154187}
0 commit comments