Skip to content

Commit 28da43a

Browse files
committed
remove dup test
1 parent b0a4810 commit 28da43a

File tree

2 files changed

+50
-121
lines changed

2 files changed

+50
-121
lines changed

packages/core/src/test/lambda/remoteDebugging/ldkController.test.ts

Lines changed: 25 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
setupMockLdkClientOperations,
2727
setupMockVSCodeDebugAPIs,
2828
setupMockRevertExistingConfig,
29+
setupDebuggingState,
30+
setupMockCleanupOperations,
2931
} from './testUtils'
3032

3133
describe('RemoteDebugController', () => {
@@ -229,6 +231,13 @@ describe('RemoteDebugController', () => {
229231
assert(mockLdkClient.createOrReuseTunnel.calledOnce, 'Should create tunnel')
230232
assert(mockLdkClient.createDebugDeployment.calledOnce, 'Should create debug deployment')
231233
assert(mockLdkClient.startProxy.calledOnce, 'Should start proxy')
234+
235+
assertTelemetry('lambda_remoteDebugStart', {
236+
result: 'Succeeded',
237+
source: 'remoteDebug',
238+
action: '{"port":9229,"remoteRoot":"/var/task","skipFiles":[],"shouldPublishVersion":false,"lambdaTimeout":900,"layerArn":"arn:aws:lambda:us-west-2:123456789012:layer:LDKLayerX86:6"}',
239+
runtimeString: 'nodejs18.x',
240+
})
232241
})
233242

234243
it('should handle debugging start failure and cleanup', async () => {
@@ -284,6 +293,13 @@ describe('RemoteDebugController', () => {
284293

285294
assert.strictEqual(controller.isDebugging, true, 'Should be in debugging state')
286295
assert.strictEqual(controller.qualifier, 'v1', 'Should set version qualifier')
296+
// Verify telemetry was emitted with version action
297+
assertTelemetry('lambda_remoteDebugStart', {
298+
result: 'Succeeded',
299+
source: 'remoteDebug',
300+
action: '{"port":9229,"remoteRoot":"/var/task","skipFiles":[],"shouldPublishVersion":true,"lambdaTimeout":900,"layerArn":"arn:aws:lambda:us-west-2:123456789012:layer:LDKLayerX86:6"}',
301+
runtimeString: 'nodejs18.x',
302+
})
287303
})
288304

289305
it('should prevent multiple debugging sessions', async () => {
@@ -303,20 +319,10 @@ describe('RemoteDebugController', () => {
303319
sandbox.stub(vscode.commands, 'executeCommand').resolves()
304320

305321
// Set up debugging state
306-
controller.isDebugging = true
307-
controller.qualifier = 'v1'
308-
309-
const mockFunctionConfig = {
310-
FunctionName: 'testFunction',
311-
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
312-
}
313-
// Set up the snapshot in mock state
314-
await mockGlobalState.update('aws.lambda.remoteDebugSnapshot', mockFunctionConfig)
322+
await setupDebuggingState(controller, mockGlobalState)
315323

316324
// Mock successful cleanup operations
317-
mockLdkClient.stopProxy.resolves(true)
318-
mockLdkClient.removeDebugDeployment.resolves(true)
319-
mockLdkClient.deleteDebugVersion.resolves(true)
325+
setupMockCleanupOperations(mockLdkClient)
320326

321327
await controller.stopDebugging()
322328

@@ -327,6 +333,9 @@ describe('RemoteDebugController', () => {
327333
assert(mockLdkClient.stopProxy.calledOnce, 'Should stop proxy')
328334
assert(mockLdkClient.removeDebugDeployment.calledOnce, 'Should remove debug deployment')
329335
assert(mockLdkClient.deleteDebugVersion.calledOnce, 'Should delete debug version')
336+
assertTelemetry('lambda_remoteDebugStop', {
337+
result: 'Succeeded',
338+
})
330339
})
331340

332341
it('should handle stop debugging when not debugging', async () => {
@@ -363,6 +372,10 @@ describe('RemoteDebugController', () => {
363372

364373
// State should still be cleaned up
365374
assert.strictEqual(controller.isDebugging, false, 'Should clean up state even on error')
375+
// Verify telemetry was emitted for failure
376+
assertTelemetry('lambda_remoteDebugStop', {
377+
result: 'Failed',
378+
})
366379
})
367380
})
368381

@@ -399,57 +412,6 @@ describe('RemoteDebugController', () => {
399412
mockFunctionConfig = createMockFunctionConfig()
400413
})
401414

402-
it('should emit lambda_remoteDebugStart telemetry for successful debugging start', async () => {
403-
// Mock VSCode APIs
404-
setupMockVSCodeDebugAPIs(sandbox)
405-
406-
// Mock runtime support
407-
sandbox.stub(controller, 'supportRuntimeRemoteDebug').returns(true)
408-
409-
// Mock successful LdkClient operations
410-
setupMockLdkClientOperations(mockLdkClient, mockFunctionConfig)
411-
412-
// Mock revertExistingConfig
413-
setupMockRevertExistingConfig(sandbox)
414-
415-
await controller.startDebugging(mockConfig.functionArn, 'nodejs18.x', mockConfig)
416-
417-
// Verify telemetry was emitted
418-
assertTelemetry('lambda_remoteDebugStart', {
419-
result: 'Succeeded',
420-
source: 'remoteDebug',
421-
action: '{"port":9229,"remoteRoot":"/var/task","skipFiles":[],"shouldPublishVersion":false,"lambdaTimeout":900,"layerArn":"arn:aws:lambda:us-west-2:123456789012:layer:LDKLayerX86:6"}',
422-
runtimeString: 'nodejs18.x',
423-
})
424-
})
425-
426-
it('should emit lambda_remoteDebugStart telemetry for version publishing', async () => {
427-
// Mock VSCode APIs
428-
setupMockVSCodeDebugAPIs(sandbox)
429-
430-
// Mock runtime support
431-
sandbox.stub(controller, 'supportRuntimeRemoteDebug').returns(true)
432-
433-
const versionConfig = { ...mockConfig, shouldPublishVersion: true }
434-
435-
// Mock successful LdkClient operations with version publishing
436-
setupMockLdkClientOperations(mockLdkClient, mockFunctionConfig)
437-
mockLdkClient.createDebugDeployment.resolves('v1')
438-
439-
// Mock revertExistingConfig
440-
setupMockRevertExistingConfig(sandbox)
441-
442-
await controller.startDebugging(versionConfig.functionArn, 'nodejs18.x', versionConfig)
443-
444-
// Verify telemetry was emitted with version action
445-
assertTelemetry('lambda_remoteDebugStart', {
446-
result: 'Succeeded',
447-
source: 'remoteDebug',
448-
action: '{"port":9229,"remoteRoot":"/var/task","skipFiles":[],"shouldPublishVersion":true,"lambdaTimeout":900,"layerArn":"arn:aws:lambda:us-west-2:123456789012:layer:LDKLayerX86:6"}',
449-
runtimeString: 'nodejs18.x',
450-
})
451-
})
452-
453415
it('should emit lambda_remoteDebugStart telemetry for failed debugging start', async () => {
454416
// Mock VSCode APIs
455417
setupMockVSCodeDebugAPIs(sandbox)
@@ -478,64 +440,6 @@ describe('RemoteDebugController', () => {
478440
runtimeString: 'nodejs18.x',
479441
})
480442
})
481-
482-
it('should emit lambda_remoteDebugStop telemetry for successful debugging stop', async () => {
483-
// Mock VSCode APIs
484-
sandbox.stub(vscode.commands, 'executeCommand').resolves()
485-
486-
// Set up debugging state
487-
controller.isDebugging = true
488-
controller.qualifier = 'v1'
489-
;(controller as any).lastDebugStartTime = Date.now() - 5000 // 5 seconds ago
490-
491-
const mockFunctionConfig = {
492-
FunctionName: 'testFunction',
493-
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
494-
}
495-
// Set up the snapshot in mock state
496-
await mockGlobalState.update('aws.lambda.remoteDebugSnapshot', mockFunctionConfig)
497-
498-
// Mock successful cleanup operations
499-
mockLdkClient.stopProxy.resolves(true)
500-
mockLdkClient.removeDebugDeployment.resolves(true)
501-
mockLdkClient.deleteDebugVersion.resolves(true)
502-
503-
await controller.stopDebugging()
504-
505-
// Verify telemetry was emitted
506-
assertTelemetry('lambda_remoteDebugStop', {
507-
result: 'Succeeded',
508-
})
509-
})
510-
511-
it('should emit lambda_remoteDebugStop telemetry for failed debugging stop', async () => {
512-
// Mock VSCode APIs
513-
sandbox.stub(vscode.commands, 'executeCommand').resolves()
514-
515-
controller.isDebugging = true
516-
517-
const mockFunctionConfig = {
518-
FunctionName: 'testFunction',
519-
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
520-
}
521-
// Set up the snapshot in mock state
522-
await mockGlobalState.update('aws.lambda.remoteDebugSnapshot', mockFunctionConfig)
523-
524-
// Mock cleanup failure
525-
mockLdkClient.stopProxy.rejects(new Error('Cleanup failed'))
526-
mockLdkClient.removeDebugDeployment.resolves(true)
527-
528-
try {
529-
await controller.stopDebugging()
530-
} catch (error) {
531-
// Expected to throw
532-
}
533-
534-
// Verify telemetry was emitted for failure
535-
assertTelemetry('lambda_remoteDebugStop', {
536-
result: 'Failed',
537-
})
538-
})
539443
})
540444
})
541445

packages/core/src/test/lambda/remoteDebugging/testUtils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,31 @@ export function createMockProgress(): any {
118118
}
119119
}
120120

121+
/**
122+
* Sets up common debugging state for stop debugging tests
123+
*/
124+
export function setupDebuggingState(controller: any, mockGlobalState: any, qualifier: string = 'v1') {
125+
controller.isDebugging = true
126+
controller.qualifier = qualifier
127+
;(controller as any).lastDebugStartTime = Date.now() - 5000 // 5 seconds ago
128+
129+
const mockFunctionConfig = {
130+
FunctionName: 'testFunction',
131+
FunctionArn: 'arn:aws:lambda:us-west-2:123456789012:function:testFunction',
132+
}
133+
134+
return mockGlobalState.update('aws.lambda.remoteDebugSnapshot', mockFunctionConfig)
135+
}
136+
137+
/**
138+
* Sets up common mock operations for successful cleanup
139+
*/
140+
export function setupMockCleanupOperations(mockLdkClient: any) {
141+
mockLdkClient.stopProxy.resolves(true)
142+
mockLdkClient.removeDebugDeployment.resolves(true)
143+
mockLdkClient.deleteDebugVersion.resolves(true)
144+
}
145+
121146
/**
122147
* Sets up common mock operations for LdkClient testing
123148
*/

0 commit comments

Comments
 (0)