|
| 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 { Ec2Connecter } from '../../../awsService/ec2/model' |
| 12 | +import { PollingSet } from '../../../shared/utilities/pollingSet' |
| 13 | + |
| 14 | +describe('ec2 activation', function () { |
| 15 | + let testNode: Ec2InstanceNode |
| 16 | + |
| 17 | + before(function () { |
| 18 | + const testRegion = 'test-region' |
| 19 | + const testPartition = 'test-partition' |
| 20 | + // Don't want to be polling here, that is tested in ../ec2ParentNode.test.ts |
| 21 | + // disabled here for convenience (avoiding race conditions with timeout) |
| 22 | + sinon.stub(PollingSet.prototype, 'start') |
| 23 | + const testClient = new Ec2Client(testRegion) |
| 24 | + const parentNode = new Ec2ParentNode(testRegion, testPartition, new Ec2Client(testRegion)) |
| 25 | + testNode = new Ec2InstanceNode(parentNode, testClient, testRegion, testPartition, { |
| 26 | + InstanceId: 'testId', |
| 27 | + LastSeenStatus: 'status', |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + after(function () { |
| 32 | + sinon.restore() |
| 33 | + }) |
| 34 | + |
| 35 | + it('telemetry', async function () { |
| 36 | + const terminalStub = sinon.stub(Ec2Connecter.prototype, 'attemptToOpenEc2Terminal') |
| 37 | + await vscode.commands.executeCommand('aws.ec2.openTerminal', testNode) |
| 38 | + |
| 39 | + assertTelemetry('ec2_connectToInstance', { ec2ConnectionType: 'ssm' }) |
| 40 | + terminalStub.restore() |
| 41 | + |
| 42 | + const stopInstanceStub = sinon.stub(Ec2Client.prototype, 'stopInstanceWithCancel') |
| 43 | + await vscode.commands.executeCommand('aws.ec2.stopInstance', testNode) |
| 44 | + |
| 45 | + assertTelemetry('ec2_changeState', { ec2InstanceState: 'stop' }) |
| 46 | + stopInstanceStub.restore() |
| 47 | + }) |
| 48 | +}) |
0 commit comments