Skip to content

Commit 0cfd826

Browse files
Muzaffer AydinMuzaffer Aydin
authored andcommitted
fix(docdb): fix jscpd errors
1 parent 50fc468 commit 0cfd826

13 files changed

+87
-105
lines changed

packages/core/src/docdb/explorer/dbClusterNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class DBClusterNode extends DBResourceNode {
152152
}
153153

154154
getLogger().debug(`Get Status: status ${cluster.Status} for cluster ${this.arn}`)
155+
155156
this.cluster.Status = cluster.Status
156157
return cluster.Status
157158
}

packages/core/src/docdb/explorer/dbElasticClusterNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,17 @@ export class DBElasticClusterNode extends DBResourceNode {
100100
await copyToClipboard(this.cluster.clusterEndpoint!, this.name)
101101
}
102102

103+
override clearTimer(): void {
104+
this.pollingSet.delete(this.arn)
105+
this.pollingSet.clearTimer()
106+
}
107+
103108
override refreshTree(): void {
104109
getLogger().debug(`(DBElasticClusterNode) Refreshing tree for instance: ${this.arn}`)
105110
this.refresh()
106111
this.parent.refresh()
107112
}
108113

109-
override clearTimer(): void {
110-
this.pollingSet.delete(this.arn)
111-
this.pollingSet.clearTimer()
112-
}
113-
114114
public override [inspect.custom](): string {
115115
return 'DBElasticClusterNode'
116116
}

packages/core/src/docdb/explorer/dbGlobalClusterNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ export class DBGlobalClusterNode extends DBResourceNode {
131131
const cluster = clusters[0]
132132

133133
if (!cluster) {
134-
getLogger().warn(`No cluster found for ARN: ${this.arn}`)
134+
getLogger().warn(`No global cluster found for ARN: ${this.arn}`)
135135
return undefined
136136
}
137137

138-
getLogger().debug(`Get Status: status ${cluster.Status} for cluster ${this.arn}`)
138+
getLogger().debug(`Get Status: status ${cluster.Status} for global cluster ${this.arn}`)
139139
this.cluster.Status = cluster.Status
140140
return cluster.Status
141141
}

packages/core/src/docdb/wizards/elasticClusterWizard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ function createShardCapacityPrompter(title: string): Prompter<number> {
118118

119119
function instanceCountItems(defaultCount: number, max: number = 16): DataQuickPickItem<number>[] {
120120
const items = []
121-
122-
for (let index = 1; index <= max; index++) {
121+
for (let i = 1; i <= max; i++) {
123122
const item: DataQuickPickItem<number> = {
124-
label: index.toString(),
125-
data: index,
126-
description: index === defaultCount ? '(recommended)' : undefined,
123+
label: i.toString(),
124+
data: i,
125+
description: i === defaultCount ? '(recommended)' : undefined,
127126
}
127+
128128
items.push(item)
129129
}
130130

packages/core/src/test/docdb/commands/addRegion.test.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ describe('addRegionCommand', function () {
2525
DBClusterMembers: [{ IsClusterWriter: true }],
2626
}
2727
let docdb: DocumentDBClient
28-
let node: DBClusterNode | DBGlobalClusterNode
29-
let sandbox: sinon.SinonSandbox
28+
let testNode: DBClusterNode | DBGlobalClusterNode
29+
let sinonSandbox: sinon.SinonSandbox
3030
let spyExecuteCommand: sinon.SinonSpy
3131

3232
beforeEach(function () {
33-
sandbox = sinon.createSandbox()
34-
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
35-
sandbox.stub(globals.regionProvider, 'isServiceInRegion').returns(true)
36-
sandbox.stub(globals.regionProvider, 'getRegions').returns([
33+
sinonSandbox = sinon.createSandbox()
34+
spyExecuteCommand = sinonSandbox.spy(vscode.commands, 'executeCommand')
35+
sinonSandbox.stub(globals.regionProvider, 'isServiceInRegion').returns(true)
36+
sinonSandbox.stub(globals.regionProvider, 'getRegions').returns([
3737
{ id: 'us-test-1', name: 'Test Region 1' },
3838
{ id: 'us-test-2', name: 'Test Region 2' },
3939
])
@@ -44,34 +44,34 @@ describe('addRegionCommand', function () {
4444
.stub()
4545
.resolves([{ DBInstanceClass: 'db.r5.large', StorageType: DBStorageType.Standard }])
4646

47-
sandbox.stub(DefaultDocumentDBClient, 'create').returns(docdb)
47+
sinonSandbox.stub(DefaultDocumentDBClient, 'create').returns(docdb)
4848

4949
cluster.DBClusterMembers = [{ IsClusterWriter: true }]
5050
const parentNode = new DocumentDBNode(docdb)
51-
node = new DBClusterNode(parentNode, cluster, docdb)
52-
})
5351

52+
testNode = new DBClusterNode(parentNode, cluster, docdb)
53+
})
5454
afterEach(function () {
55-
sandbox.restore()
55+
sinonSandbox.restore()
5656
getTestWindow().dispose()
5757
})
58-
5958
function setupWizard() {
6059
getTestWindow().onDidShowInputBox((input) => {
61-
let value: string
60+
let val: string
61+
6262
if (input.prompt?.includes('global')) {
63-
value = globalClusterName
63+
val = globalClusterName
6464
} else if (input.prompt?.includes('cluster name')) {
65-
value = clusterName
65+
val = clusterName
6666
} else {
67-
value = ''
67+
val = ''
6868
}
69-
input.acceptValue(value)
69+
input.acceptValue(val)
7070
})
7171

72-
getTestWindow().onDidShowQuickPick(async (picker) => {
73-
await picker.untilReady()
74-
picker.acceptItem(picker.items[0])
72+
getTestWindow().onDidShowQuickPick(async (testQuickPicker) => {
73+
await testQuickPicker.untilReady()
74+
testQuickPicker.acceptItem(testQuickPicker.items[0])
7575
})
7676
}
7777

@@ -83,14 +83,15 @@ describe('addRegionCommand', function () {
8383
const createClusterStub = sinon.stub().resolves({
8484
DBClusterIdentifier: clusterName,
8585
})
86-
const createInstanceStub = sinon.stub().resolves()
86+
const createInstanceSinonStub = sinon.stub().resolves()
8787
docdb.createGlobalCluster = createGlobalClusterStub
8888
docdb.createCluster = createClusterStub
89-
docdb.createInstance = createInstanceStub
89+
docdb.createInstance = createInstanceSinonStub
90+
9091
setupWizard()
9192

9293
// act
93-
await addRegion(node)
94+
await addRegion(testNode)
9495

9596
// assert
9697
getTestWindow().getFirstMessage().assertInfo('Region added')
@@ -110,9 +111,8 @@ describe('addRegionCommand', function () {
110111
})
111112
)
112113
)
113-
114114
assert(
115-
createInstanceStub.calledOnceWith(
115+
createInstanceSinonStub.calledOnceWith(
116116
sinon.match({
117117
Engine: 'docdb',
118118
DBClusterIdentifier: clusterName,
@@ -122,7 +122,7 @@ describe('addRegionCommand', function () {
122122
)
123123
)
124124

125-
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node.parent)
125+
sinonSandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', testNode.parent)
126126

127127
assertTelemetry('docdb_addRegion', { result: 'Succeeded' })
128128
})
@@ -132,12 +132,12 @@ describe('addRegionCommand', function () {
132132
const createGlobalClusterStub = sinon.stub().resolves({
133133
GlobalClusterIdentifier: globalClusterName,
134134
})
135-
const createClusterStub = sinon.stub().resolves({
135+
const createClusterSinonStub = sinon.stub().resolves({
136136
DBClusterIdentifier: clusterName,
137137
})
138138
const createInstanceStub = sinon.stub().resolves()
139139
docdb.createGlobalCluster = createGlobalClusterStub
140-
docdb.createCluster = createClusterStub
140+
docdb.createCluster = createClusterSinonStub
141141
docdb.createInstance = createInstanceStub
142142
setupWizard()
143143

@@ -146,18 +146,18 @@ describe('addRegionCommand', function () {
146146
GlobalClusterMembers: [],
147147
Status: 'available',
148148
}
149-
node = new DBGlobalClusterNode(new DocumentDBNode(docdb), globalCluster, new Map(), docdb)
149+
testNode = new DBGlobalClusterNode(new DocumentDBNode(docdb), globalCluster, new Map(), docdb)
150150

151151
// act
152-
await addRegion(node)
152+
await addRegion(testNode)
153153

154154
// assert
155155
getTestWindow().getFirstMessage().assertInfo('Region added')
156156

157157
assert(createGlobalClusterStub.notCalled)
158158

159159
assert(
160-
createClusterStub.calledOnceWith(
160+
createClusterSinonStub.calledOnceWith(
161161
sinon.match({
162162
DBClusterIdentifier: clusterName,
163163
GlobalClusterIdentifier: globalClusterName,
@@ -175,8 +175,7 @@ describe('addRegionCommand', function () {
175175
})
176176
)
177177
)
178-
179-
sandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', node)
178+
sinonSandbox.assert.calledWith(spyExecuteCommand, 'aws.refreshAwsExplorerNode', testNode)
180179

181180
assertTelemetry('docdb_addRegion', { result: 'Succeeded' })
182181
})
@@ -188,7 +187,7 @@ describe('addRegionCommand', function () {
188187
getTestWindow().onDidShowQuickPick((input) => input.hide())
189188

190189
// act
191-
await assert.rejects(addRegion(node))
190+
await assert.rejects(addRegion(testNode))
192191

193192
// assert
194193
assert(stub.notCalled)
@@ -205,7 +204,7 @@ describe('addRegionCommand', function () {
205204
setupWizard()
206205

207206
// act
208-
await assert.rejects(addRegion(node))
207+
await assert.rejects(addRegion(testNode))
209208

210209
// assert
211210
getTestWindow()
@@ -217,12 +216,12 @@ describe('addRegionCommand', function () {
217216

218217
it('shows a warning when the cluster has no instances', async function () {
219218
// arrange
220-
const clusterNode = node as DBClusterNode
219+
const clusterNode = testNode as DBClusterNode
221220
clusterNode.cluster.DBClusterMembers = []
222221
setupWizard()
223222

224223
// act
225-
await assert.rejects(addRegion(node))
224+
await assert.rejects(addRegion(testNode))
226225

227226
// assert
228227
getTestWindow()
@@ -234,12 +233,12 @@ describe('addRegionCommand', function () {
234233

235234
it('shows a warning when the cluster has an unsupported instance class', async function () {
236235
// arrange
237-
const clusterNode = node as DBClusterNode
236+
const clusterNode = testNode as DBClusterNode
238237
clusterNode.instances = [{ DBInstanceClass: 'db.t3.medium' }]
239238
setupWizard()
240239

241240
// act
242-
await assert.rejects(addRegion(node))
241+
await assert.rejects(addRegion(testNode))
243242

244243
// assert
245244
getTestWindow()

packages/core/src/test/docdb/commands/createCluster.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { createCluster } from '../../../docdb/commands/createCluster'
1414

1515
describe('createClusterCommand', function () {
1616
const clusterName = 'docdb-1234'
17-
const username = 'testuser'
18-
const password = 'test-password'
17+
const testUser = 'testuser'
18+
const testPassword = 'test-password'
1919
let docdb: DocumentDBClient
2020
let node: DocumentDBNode
2121
let sandbox: sinon.SinonSandbox
@@ -43,17 +43,16 @@ describe('createClusterCommand', function () {
4343
getTestWindow().onDidShowInputBox((input) => {
4444
let value: string
4545
if (input.prompt?.includes('username')) {
46-
value = username
46+
value = testUser
4747
} else if (input.prompt?.includes('password')) {
48-
value = password
48+
value = testPassword
4949
} else if (input.prompt?.includes('cluster name')) {
5050
value = clusterName
5151
} else {
5252
value = ''
5353
}
5454
input.acceptValue(value)
5555
})
56-
5756
getTestWindow().onDidShowQuickPick(async (picker) => {
5857
await picker.untilReady()
5958
picker.acceptItem(picker.items[0])
@@ -85,8 +84,8 @@ describe('createClusterCommand', function () {
8584
Engine: 'docdb',
8685
EngineVersion: 'test-version',
8786
DBClusterIdentifier: clusterName,
88-
MasterUsername: username,
89-
MasterUserPassword: password,
87+
MasterUsername: testUser,
88+
MasterUserPassword: testPassword,
9089
StorageEncrypted: true,
9190
DBInstanceCount: 1,
9291
DBInstanceClass: 'db.t3.medium',

packages/core/src/test/docdb/commands/createInstance.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ describe('createInstanceCommand', function () {
2020
let docdb: DocumentDBClient
2121
let cluster: DBCluster
2222
let node: DBClusterNode
23-
let sandbox: sinon.SinonSandbox
2423
let spyExecuteCommand: sinon.SinonSpy
24+
let sandbox: sinon.SinonSandbox
2525

2626
beforeEach(function () {
2727
sandbox = sinon.createSandbox()
2828
spyExecuteCommand = sandbox.spy(vscode.commands, 'executeCommand')
2929

3030
docdb = { regionCode: 'us-east-1' } as DocumentDBClient
31+
3132
docdb.listInstances = sinon.stub().resolves([])
33+
3234
docdb.listInstanceClassOptions = sinon
3335
.stub()
3436
.resolves([{ DBInstanceClass: 'db.t3.medium', StorageType: DBStorageType.Standard }])
@@ -42,7 +44,6 @@ describe('createInstanceCommand', function () {
4244
sandbox.restore()
4345
getTestWindow().dispose()
4446
})
45-
4647
function setupWizard() {
4748
getTestWindow().onDidShowInputBox((input) => {
4849
input.acceptValue(instanceName)

0 commit comments

Comments
 (0)