Skip to content

Commit 04864de

Browse files
Strum355claude
andcommitted
test: use real go binary in Go workspace discovery tests
Replace esmock invokeCommand mocks with real `go work edit -json` invocations for happy-path tests. Keep esmock only for error paths that cannot be reproduced with a real binary (command failure, invalid JSON output). Add go_workspace_empty fixture for the null-Use case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 13c5a8e commit 04864de

2 files changed

Lines changed: 7 additions & 81 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go 1.22

test/providers/workspace.test.js

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,6 @@ suite('discoverGoWorkspaceModules', () => {
332332

333333
test('discovers modules from go.work with two modules', async () => {
334334
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace')
335-
const goWorkJson = {
336-
Go: { Version: '1.22' },
337-
Use: [
338-
{ DiskPath: './module-a' },
339-
{ DiskPath: './module-b' },
340-
],
341-
}
342-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
343-
'../../src/tools.js': {
344-
getCustom: () => null,
345-
getCustomPath: () => 'go',
346-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
347-
},
348-
})
349335
const result = await discoverGoWorkspaceModules(root)
350336
expect(result).to.be.an('array')
351337
expect(result).to.have.lengthOf(2)
@@ -356,20 +342,6 @@ suite('discoverGoWorkspaceModules', () => {
356342

357343
test('discovers modules from nested directories', async () => {
358344
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace_nested')
359-
const goWorkJson = {
360-
Go: { Version: '1.22' },
361-
Use: [
362-
{ DiskPath: './libs/core' },
363-
{ DiskPath: './libs/util' },
364-
],
365-
}
366-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
367-
'../../src/tools.js': {
368-
getCustom: () => null,
369-
getCustomPath: () => 'go',
370-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
371-
},
372-
})
373345
const result = await discoverGoWorkspaceModules(root)
374346
expect(result).to.have.lengthOf(2)
375347
expect(result.some(p => p.includes(path.join('libs', 'core', 'go.mod')))).to.be.true
@@ -378,99 +350,52 @@ suite('discoverGoWorkspaceModules', () => {
378350

379351
test('discovers single module', async () => {
380352
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace_single')
381-
const goWorkJson = {
382-
Go: { Version: '1.22' },
383-
Use: [{ DiskPath: './mymod' }],
384-
}
385-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
386-
'../../src/tools.js': {
387-
getCustom: () => null,
388-
getCustomPath: () => 'go',
389-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
390-
},
391-
})
392353
const result = await discoverGoWorkspaceModules(root)
393354
expect(result).to.have.lengthOf(1)
394355
expect(result[0]).to.include(path.join('mymod', 'go.mod'))
395356
})
396357

397358
test('skips modules whose directory does not exist', async () => {
398359
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace_missing_module')
399-
const goWorkJson = {
400-
Go: { Version: '1.22' },
401-
Use: [
402-
{ DiskPath: './existing' },
403-
{ DiskPath: './nonexistent' },
404-
],
405-
}
406-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
407-
'../../src/tools.js': {
408-
getCustom: () => null,
409-
getCustomPath: () => 'go',
410-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
411-
},
412-
})
413360
const result = await discoverGoWorkspaceModules(root)
414361
expect(result).to.have.lengthOf(1)
415362
expect(result[0]).to.include(path.join('existing', 'go.mod'))
416363
})
417364

418365
test('returns empty when go command fails', async () => {
419366
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace')
420-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
367+
const { discoverGoWorkspaceModules: discoverMocked } = await esmock('../../src/providers/golang_gomodules.js', {
421368
'../../src/tools.js': {
422369
getCustom: () => null,
423370
getCustomPath: () => 'go',
424371
invokeCommand: () => { throw new Error('go not found') },
425372
},
426373
})
427-
const result = await discoverGoWorkspaceModules(root)
374+
const result = await discoverMocked(root)
428375
expect(result).to.have.lengthOf(0)
429376
})
430377

431378
test('returns empty when go output is invalid JSON', async () => {
432379
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace')
433-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
380+
const { discoverGoWorkspaceModules: discoverMocked } = await esmock('../../src/providers/golang_gomodules.js', {
434381
'../../src/tools.js': {
435382
getCustom: () => null,
436383
getCustomPath: () => 'go',
437384
invokeCommand: () => Buffer.from('not json'),
438385
},
439386
})
440-
const result = await discoverGoWorkspaceModules(root)
387+
const result = await discoverMocked(root)
441388
expect(result).to.have.lengthOf(0)
442389
})
443390

444-
test('returns empty when Use array is empty', async () => {
445-
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace')
446-
const goWorkJson = { Go: { Version: '1.22' }, Use: [] }
447-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
448-
'../../src/tools.js': {
449-
getCustom: () => null,
450-
getCustomPath: () => 'go',
451-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
452-
},
453-
})
391+
test('returns empty when Use is null (no use directives)', async () => {
392+
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace_empty')
454393
const result = await discoverGoWorkspaceModules(root)
455394
expect(result).to.have.lengthOf(0)
456395
})
457396

458397
test('applies ignore patterns to discovered modules', async () => {
459398
const root = path.resolve('test/providers/tst_manifests/golang/go_workspace_nested')
460-
const goWorkJson = {
461-
Go: { Version: '1.22' },
462-
Use: [
463-
{ DiskPath: './libs/core' },
464-
{ DiskPath: './libs/util' },
465-
],
466-
}
467-
const { discoverGoWorkspaceModules } = await esmock('../../src/providers/golang_gomodules.js', {
468-
'../../src/tools.js': {
469-
getCustom: () => null,
470-
getCustomPath: () => 'go',
471-
invokeCommand: () => Buffer.from(JSON.stringify(goWorkJson)),
472-
},
473-
})
474399
const result = await discoverGoWorkspaceModules(root, {
475400
workspaceDiscoveryIgnore: ['**/util/**'],
476401
})

0 commit comments

Comments
 (0)