Skip to content

Commit 4dd59ff

Browse files
committed
move shared data to one place
1 parent 084c1b4 commit 4dd59ff

File tree

5 files changed

+25
-82
lines changed

5 files changed

+25
-82
lines changed

packages/core/src/test/awsService/ec2/explorer/ec2InstanceNode.test.ts

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,23 @@ import {
1212
Ec2InstanceStoppedContext,
1313
refreshExplorerNode,
1414
} from '../../../../awsService/ec2/explorer/ec2InstanceNode'
15-
import { Ec2Client, SafeEc2Instance, getNameOfInstance } from '../../../../shared/clients/ec2Client'
15+
import { Ec2Client, getNameOfInstance } from '../../../../shared/clients/ec2Client'
1616
import { Ec2ParentNode } from '../../../../awsService/ec2/explorer/ec2ParentNode'
1717
import { DefaultAwsContext } from '../../../../shared'
18+
import { testClient, testInstance, testParentNode } from './ec2ParentNode.test'
1819

1920
describe('ec2InstanceNode', function () {
2021
let testNode: Ec2InstanceNode
21-
let testInstance: SafeEc2Instance
22-
const testRegion = 'testRegion'
23-
const testPartition = 'testPartition'
24-
2522
before(function () {
26-
testInstance = {
27-
InstanceId: 'testId',
28-
Tags: [
29-
{
30-
Key: 'Name',
31-
Value: 'testName',
32-
},
33-
],
34-
LastSeenStatus: 'running',
35-
}
36-
const testClient = new Ec2Client('')
37-
const testParentNode = new Ec2ParentNode(testRegion, testPartition, testClient)
23+
sinon.stub(DefaultAwsContext.prototype, 'getCredentialAccountId')
3824
testNode = new Ec2InstanceNode(testParentNode, testClient, 'testRegion', 'testPartition', testInstance)
3925
})
4026

41-
this.beforeEach(function () {
27+
after(function () {
28+
sinon.restore()
29+
})
30+
31+
beforeEach(function () {
4232
testNode.updateInstance(testInstance)
4333
})
4434

@@ -97,34 +87,7 @@ describe('ec2InstanceNode', function () {
9787
})
9888

9989
describe('refreshExplorerNode', function () {
100-
let testInstance: SafeEc2Instance
101-
let testParentNode: Ec2ParentNode
102-
let testClient: Ec2Client
103-
let testNode: Ec2InstanceNode
104-
105-
before(function () {
106-
sinon.stub(DefaultAwsContext.prototype, 'getCredentialAccountId')
107-
testInstance = {
108-
InstanceId: 'testId',
109-
Tags: [
110-
{
111-
Key: 'Name',
112-
Value: 'testName',
113-
},
114-
],
115-
LastSeenStatus: 'running',
116-
}
117-
testClient = new Ec2Client('')
118-
testParentNode = new Ec2ParentNode('fake-region', 'testPartition', testClient)
119-
testNode = new Ec2InstanceNode(testParentNode, testClient, 'testRegion', 'testPartition', testInstance)
120-
})
121-
122-
after(function () {
123-
sinon.restore()
124-
})
125-
12690
it('refreshes only parent node', async function () {
127-
const testParentNode = new Ec2ParentNode('fake-region', 'testPartition', testClient)
12891
const parentRefresh = sinon.stub(Ec2ParentNode.prototype, 'refreshNode')
12992
const childRefresh = sinon.stub(Ec2InstanceNode.prototype, 'refreshNode')
13093

packages/core/src/test/awsService/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ import * as FakeTimers from '@sinonjs/fake-timers'
1919
import { installFakeClock } from '../../../testUtil'
2020
import { PollingSet } from '../../../../shared/utilities/pollingSet'
2121

22+
export const testInstance = {
23+
InstanceId: 'testId',
24+
Tags: [
25+
{
26+
Key: 'Name',
27+
Value: 'testName',
28+
},
29+
],
30+
LastSeenStatus: 'running',
31+
}
32+
export const testClient = new Ec2Client('')
33+
export const testParentNode = new Ec2ParentNode('fake-region', 'testPartition', testClient)
34+
2235
describe('ec2ParentNode', function () {
2336
let testNode: Ec2ParentNode
2437
let defaultInstances: SafeEc2Instance[]

packages/core/src/test/awsService/ec2/prompter.test.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import assert from 'assert'
66
import * as sinon from 'sinon'
77
import { Ec2Prompter, getSelection, instanceFilter } from '../../../awsService/ec2/prompter'
8-
import { Ec2Client, SafeEc2Instance } from '../../../shared/clients/ec2Client'
8+
import { SafeEc2Instance } from '../../../shared/clients/ec2Client'
99
import { RegionSubmenuResponse } from '../../../shared/ui/common/regionSubmenu'
1010
import { Ec2Selection } from '../../../awsService/ec2/prompter'
1111
import { AsyncCollection } from '../../../shared/utilities/asyncCollection'
1212
import { intoCollection } from '../../../shared/utilities/collectionUtils'
1313
import { DataQuickPickItem } from '../../../shared/ui/pickerPrompter'
14-
import { Ec2ParentNode } from '../../../awsService/ec2/explorer/ec2ParentNode'
1514
import { Ec2InstanceNode } from '../../../awsService/ec2/explorer/ec2InstanceNode'
15+
import { testClient, testInstance, testParentNode } from './explorer/ec2ParentNode.test'
1616

1717
describe('Ec2Prompter', async function () {
1818
class MockEc2Prompter extends Ec2Prompter {
@@ -189,27 +189,14 @@ describe('Ec2Prompter', async function () {
189189

190190
describe('getSelection', async function () {
191191
it('uses node when passed', async function () {
192-
const testInstance = {
193-
InstanceId: 'testId',
194-
Tags: [
195-
{
196-
Key: 'Name',
197-
Value: 'testName',
198-
},
199-
],
200-
LastSeenStatus: 'running',
201-
}
202-
const testClient = new Ec2Client('')
203-
const testParentNode = new Ec2ParentNode('fake-region', 'testPartition', testClient)
192+
const prompterStub = sinon.stub(Ec2Prompter.prototype, 'promptUser')
204193
const testNode = new Ec2InstanceNode(
205194
testParentNode,
206195
testClient,
207196
'testRegion',
208197
'testPartition',
209198
testInstance
210199
)
211-
212-
const prompterStub = sinon.stub(Ec2Prompter.prototype, 'promptUser')
213200
const result = await getSelection(testNode)
214201

215202
assert.strictEqual(result.instanceId, testNode.toSelection().instanceId)

packages/core/src/test/awsService/ec2/utils.test.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,13 @@
55

66
import assert from 'assert'
77
import * as sinon from 'sinon'
8-
import { Ec2Client, SafeEc2Instance } from '../../../shared/clients/ec2Client'
8+
import { SafeEc2Instance } from '../../../shared/clients/ec2Client'
99
import { getIconCode } from '../../../awsService/ec2/utils'
10-
import { Ec2InstanceNode } from '../../../awsService/ec2/explorer/ec2InstanceNode'
11-
import { Ec2ParentNode } from '../../../awsService/ec2/explorer/ec2ParentNode'
1210
import { DefaultAwsContext } from '../../../shared'
1311

1412
describe('utils', async function () {
15-
let testInstance: SafeEc2Instance
16-
let testParentNode: Ec2ParentNode
17-
let testClient: Ec2Client
18-
let testNode: Ec2InstanceNode
19-
2013
before(function () {
2114
sinon.stub(DefaultAwsContext.prototype, 'getCredentialAccountId')
22-
testInstance = {
23-
InstanceId: 'testId',
24-
Tags: [
25-
{
26-
Key: 'Name',
27-
Value: 'testName',
28-
},
29-
],
30-
LastSeenStatus: 'running',
31-
}
32-
testClient = new Ec2Client('')
33-
testParentNode = new Ec2ParentNode('fake-region', 'testPartition', testClient)
34-
testNode = new Ec2InstanceNode(testParentNode, testClient, 'testRegion', 'testPartition', testInstance)
3515
})
3616

3717
after(function () {

0 commit comments

Comments
 (0)