@@ -198,20 +198,6 @@ suite('discoverGoWorkspaceModules', () => {
198198
199199 test ( 'discovers modules from go.work with two modules' , async ( ) => {
200200 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace' )
201- const goWorkJson = {
202- Go : { Version : '1.22' } ,
203- Use : [
204- { DiskPath : './module-a' } ,
205- { DiskPath : './module-b' } ,
206- ] ,
207- }
208- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
209- '../../src/tools.js' : {
210- getCustom : ( ) => null ,
211- getCustomPath : ( ) => 'go' ,
212- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
213- } ,
214- } )
215201 const result = await discoverGoWorkspaceModules ( root )
216202 expect ( result ) . to . be . an ( 'array' )
217203 expect ( result ) . to . have . lengthOf ( 2 )
@@ -222,20 +208,6 @@ suite('discoverGoWorkspaceModules', () => {
222208
223209 test ( 'discovers modules from nested directories' , async ( ) => {
224210 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace_nested' )
225- const goWorkJson = {
226- Go : { Version : '1.22' } ,
227- Use : [
228- { DiskPath : './libs/core' } ,
229- { DiskPath : './libs/util' } ,
230- ] ,
231- }
232- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
233- '../../src/tools.js' : {
234- getCustom : ( ) => null ,
235- getCustomPath : ( ) => 'go' ,
236- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
237- } ,
238- } )
239211 const result = await discoverGoWorkspaceModules ( root )
240212 expect ( result ) . to . have . lengthOf ( 2 )
241213 expect ( result . some ( p => p . includes ( path . join ( 'libs' , 'core' , 'go.mod' ) ) ) ) . to . be . true
@@ -244,99 +216,52 @@ suite('discoverGoWorkspaceModules', () => {
244216
245217 test ( 'discovers single module' , async ( ) => {
246218 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace_single' )
247- const goWorkJson = {
248- Go : { Version : '1.22' } ,
249- Use : [ { DiskPath : './mymod' } ] ,
250- }
251- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
252- '../../src/tools.js' : {
253- getCustom : ( ) => null ,
254- getCustomPath : ( ) => 'go' ,
255- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
256- } ,
257- } )
258219 const result = await discoverGoWorkspaceModules ( root )
259220 expect ( result ) . to . have . lengthOf ( 1 )
260221 expect ( result [ 0 ] ) . to . include ( path . join ( 'mymod' , 'go.mod' ) )
261222 } )
262223
263224 test ( 'skips modules whose directory does not exist' , async ( ) => {
264225 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace_missing_module' )
265- const goWorkJson = {
266- Go : { Version : '1.22' } ,
267- Use : [
268- { DiskPath : './existing' } ,
269- { DiskPath : './nonexistent' } ,
270- ] ,
271- }
272- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
273- '../../src/tools.js' : {
274- getCustom : ( ) => null ,
275- getCustomPath : ( ) => 'go' ,
276- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
277- } ,
278- } )
279226 const result = await discoverGoWorkspaceModules ( root )
280227 expect ( result ) . to . have . lengthOf ( 1 )
281228 expect ( result [ 0 ] ) . to . include ( path . join ( 'existing' , 'go.mod' ) )
282229 } )
283230
284231 test ( 'returns empty when go command fails' , async ( ) => {
285232 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace' )
286- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
233+ const { discoverGoWorkspaceModules : discoverMocked } = await esmock ( '../../src/providers/golang_gomodules.js' , {
287234 '../../src/tools.js' : {
288235 getCustom : ( ) => null ,
289236 getCustomPath : ( ) => 'go' ,
290237 invokeCommand : ( ) => { throw new Error ( 'go not found' ) } ,
291238 } ,
292239 } )
293- const result = await discoverGoWorkspaceModules ( root )
240+ const result = await discoverMocked ( root )
294241 expect ( result ) . to . have . lengthOf ( 0 )
295242 } )
296243
297244 test ( 'returns empty when go output is invalid JSON' , async ( ) => {
298245 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace' )
299- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
246+ const { discoverGoWorkspaceModules : discoverMocked } = await esmock ( '../../src/providers/golang_gomodules.js' , {
300247 '../../src/tools.js' : {
301248 getCustom : ( ) => null ,
302249 getCustomPath : ( ) => 'go' ,
303250 invokeCommand : ( ) => Buffer . from ( 'not json' ) ,
304251 } ,
305252 } )
306- const result = await discoverGoWorkspaceModules ( root )
253+ const result = await discoverMocked ( root )
307254 expect ( result ) . to . have . lengthOf ( 0 )
308255 } )
309256
310- test ( 'returns empty when Use array is empty' , async ( ) => {
311- const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace' )
312- const goWorkJson = { Go : { Version : '1.22' } , Use : [ ] }
313- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
314- '../../src/tools.js' : {
315- getCustom : ( ) => null ,
316- getCustomPath : ( ) => 'go' ,
317- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
318- } ,
319- } )
257+ test ( 'returns empty when Use is null (no use directives)' , async ( ) => {
258+ const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace_empty' )
320259 const result = await discoverGoWorkspaceModules ( root )
321260 expect ( result ) . to . have . lengthOf ( 0 )
322261 } )
323262
324263 test ( 'applies ignore patterns to discovered modules' , async ( ) => {
325264 const root = path . resolve ( 'test/providers/tst_manifests/golang/go_workspace_nested' )
326- const goWorkJson = {
327- Go : { Version : '1.22' } ,
328- Use : [
329- { DiskPath : './libs/core' } ,
330- { DiskPath : './libs/util' } ,
331- ] ,
332- }
333- const { discoverGoWorkspaceModules } = await esmock ( '../../src/providers/golang_gomodules.js' , {
334- '../../src/tools.js' : {
335- getCustom : ( ) => null ,
336- getCustomPath : ( ) => 'go' ,
337- invokeCommand : ( ) => Buffer . from ( JSON . stringify ( goWorkJson ) ) ,
338- } ,
339- } )
340265 const result = await discoverGoWorkspaceModules ( root , {
341266 workspaceDiscoveryIgnore : [ '**/util/**' ] ,
342267 } )
0 commit comments