@@ -139,29 +139,57 @@ public async Task Go117ModDetector_GoModFileFound_GoModParserIsExecuted()
139
139
goModParserMock . Verify ( parser => parser . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) , Times . Once ) ;
140
140
}
141
141
142
- [ TestMethod ]
143
- public async Task Go117ModDetector_GoSumFileFound_GoSumParserIsExecuted ( )
142
+ /// <summary>
143
+ /// Verifies that if Go CLI is enabled/available and succeeds, go.sum file is not parsed and vice-versa.
144
+ /// </summary>
145
+ /// <returns>Task.</returns>
146
+ [ DataTestMethod ]
147
+ [ DataRow ( true ) ]
148
+ [ DataRow ( false ) ]
149
+ public async Task Go117Detector_GoSum_GoSumParserExecuted ( bool goCliSucceeds )
144
150
{
151
+ var nInvocationsOfSumParser = goCliSucceeds ? 0 : 1 ;
145
152
var goSumParserMock = new Mock < IGoParser > ( ) ;
153
+ var goCliParserMock = new Mock < IGoParser > ( ) ;
146
154
this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoSum , It . IsAny < ILogger > ( ) ) ) . Returns ( goSumParserMock . Object ) ;
155
+ this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoCLI , It . IsAny < ILogger > ( ) ) ) . Returns ( goCliParserMock . Object ) ;
147
156
148
- this . commandLineMock . Setup ( x => x . CanCommandBeLocatedAsync ( "go" , null , null , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
149
- . ReturnsAsync ( true ) ;
157
+ // Setup go cli parser to succeed/fail
158
+ goCliParserMock . Setup ( p => p . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) ) . ReturnsAsync ( goCliSucceeds ) ;
150
159
151
- this . commandLineMock . Setup ( x => x . ExecuteCommandAsync ( "go" , null , null , default , It . Is < string [ ] > ( p => p . SequenceEqual ( new List < string > { "version" } . ToArray ( ) ) ) ) )
152
- . ReturnsAsync ( new CommandLineExecutionResult
153
- {
154
- ExitCode = 0 ,
155
- StdOut = "go version go1.10.6 windows/amd64" ,
156
- } ) ;
160
+ // Setup go sum parser to succeed
161
+ goSumParserMock . Setup ( p => p . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) ) . ReturnsAsync ( true ) ;
157
162
158
163
var ( scanResult , componentRecorder ) = await this . DetectorTestUtility
159
164
. WithFile ( "go.sum" , string . Empty )
160
165
. ExecuteDetectorAsync ( ) ;
161
166
162
167
scanResult . ResultCode . Should ( ) . Be ( ProcessingResultCode . Success ) ;
168
+ this . mockParserFactory . Verify ( clm => clm . CreateParser ( GoParserType . GoSum , It . IsAny < ILogger > ( ) ) , nInvocationsOfSumParser == 0 ? Times . Never : Times . Once ) ;
169
+ }
170
+
171
+ /// <summary>
172
+ /// Verifies that if Go CLI is disabled, go.sum is parsed.
173
+ /// </summary>
174
+ /// <returns>Task.</returns>
175
+ [ TestMethod ]
176
+ public async Task Go117Detector_GoSum_GoSumParserExecutedIfCliDisabled ( )
177
+ {
178
+ var goSumParserMock = new Mock < IGoParser > ( ) ;
179
+ this . mockParserFactory . Setup ( x => x . CreateParser ( GoParserType . GoSum , It . IsAny < ILogger > ( ) ) ) . Returns ( goSumParserMock . Object ) ;
180
+
181
+ // Setup environment variable to disable CLI scan
182
+ this . envVarService . Setup ( s => s . IsEnvironmentVariableValueTrue ( "DisableGoCliScan" ) ) . Returns ( true ) ;
183
+
184
+ // Setup go sum parser to succed
185
+ goSumParserMock . Setup ( p => p . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) ) . ReturnsAsync ( true ) ;
163
186
164
- goSumParserMock . Verify ( parser => parser . ParseAsync ( It . IsAny < ISingleFileComponentRecorder > ( ) , It . IsAny < IComponentStream > ( ) , It . IsAny < GoGraphTelemetryRecord > ( ) ) , Times . Once ) ;
187
+ var ( scanResult , componentRecorder ) = await this . DetectorTestUtility
188
+ . WithFile ( "go.sum" , string . Empty )
189
+ . ExecuteDetectorAsync ( ) ;
190
+
191
+ scanResult . ResultCode . Should ( ) . Be ( ProcessingResultCode . Success ) ;
192
+ this . mockParserFactory . Verify ( clm => clm . CreateParser ( GoParserType . GoSum , It . IsAny < ILogger > ( ) ) , Times . Once ) ;
165
193
}
166
194
167
195
[ TestMethod ]
0 commit comments