Skip to content

Commit ea2a1ce

Browse files
committed
add tests for telemetry
1 parent 3dae58c commit ea2a1ce

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import * as vscode from 'vscode'
6+
import * as sinon from 'sinon'
7+
import { assertTelemetry } from '../../testUtil'
8+
import { Ec2InstanceNode } from '../../../awsService/ec2/explorer/ec2InstanceNode'
9+
import { Ec2ParentNode } from '../../../awsService/ec2/explorer/ec2ParentNode'
10+
import { Ec2Client } from '../../../shared/clients/ec2Client'
11+
import { Ec2ConnectionManager } from '../../../awsService/ec2/model'
12+
13+
describe('ec2 telemetry', function () {
14+
let testNode: Ec2InstanceNode
15+
16+
before(function () {
17+
const testRegion = 'test-region'
18+
const testPartition = 'test-partition'
19+
const testClient = new Ec2Client(testRegion)
20+
const parentNode = new Ec2ParentNode(testRegion, testPartition, new Ec2Client(testRegion))
21+
testNode = new Ec2InstanceNode(parentNode, testClient, testRegion, testPartition, {
22+
InstanceId: 'testId',
23+
LastSeenStatus: 'status',
24+
})
25+
})
26+
it('emits correct telemetry on terminal open', async function () {
27+
const terminalStub = sinon.stub(Ec2ConnectionManager.prototype, 'attemptToOpenEc2Terminal')
28+
await vscode.commands.executeCommand('aws.ec2.openTerminal', testNode)
29+
30+
assertTelemetry('ec2_connectToInstance', { ec2ConnectionType: 'ssm' })
31+
terminalStub.restore()
32+
})
33+
34+
it('emits correct telemetry on remote window open', async function () {
35+
const remoteWindowStub = sinon.stub(Ec2ConnectionManager.prototype, 'tryOpenRemoteConnection')
36+
await vscode.commands.executeCommand('aws.ec2.openRemoteConnection', testNode)
37+
38+
assertTelemetry('ec2_connectToInstance', { ec2ConnectionType: 'remoteWorkspace' })
39+
remoteWindowStub.restore()
40+
})
41+
42+
it('emits correct telemetry on state stop', async function () {
43+
const stopInstanceStub = sinon.stub(Ec2Client.prototype, 'stopInstanceWithCancel')
44+
await vscode.commands.executeCommand('aws.ec2.stopInstance', testNode)
45+
46+
assertTelemetry('ec2_changeState', { ec2InstanceState: 'stop' })
47+
stopInstanceStub.restore()
48+
})
49+
50+
it('emits correct telemetry on state start', async function () {
51+
const startInstanceStub = sinon.stub(Ec2Client.prototype, 'startInstance')
52+
await vscode.commands.executeCommand('aws.ec2.startInstance', testNode)
53+
54+
assertTelemetry('ec2_changeState', { ec2InstanceState: 'start' })
55+
startInstanceStub.restore()
56+
})
57+
58+
it('emits correct telemetry on state reboot', async function () {
59+
const rebootInstanceStub = sinon.stub(Ec2Client.prototype, 'rebootInstance')
60+
await vscode.commands.executeCommand('aws.ec2.rebootInstance', testNode)
61+
62+
assertTelemetry('ec2_changeState', { ec2InstanceState: 'reboot' })
63+
rebootInstanceStub.restore()
64+
})
65+
})

0 commit comments

Comments
 (0)