Skip to content

Commit f97fd57

Browse files
committed
👌 fix unit tests
1 parent a7184af commit f97fd57

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

‎scripts/deploy/deploy-prod-dc.spec.ts‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import assert from 'node:assert/strict'
22
import path from 'node:path'
3-
import { beforeEach, before, describe, it, mock } from 'node:test'
3+
import { beforeEach, before, describe, it, mock, afterEach } from 'node:test'
44
import type { CommandDetail } from './lib/testHelpers.ts'
5-
import { mockModule, mockCommandImplementation } from './lib/testHelpers.ts'
5+
import { mockCommandImplementation, mockModule } from './lib/testHelpers.ts'
66

7-
// eslint-disable-next-line
8-
describe.only('deploy-prod-dc', () => {
7+
describe('deploy-prod-dc', () => {
98
const commandMock = mock.fn()
10-
119
let commands: CommandDetail[]
1210

1311
before(async () => {
@@ -21,6 +19,10 @@ describe.only('deploy-prod-dc', () => {
2119
commands = mockCommandImplementation(commandMock)
2220
})
2321

22+
afterEach(() => {
23+
mock.restoreAll()
24+
})
25+
2426
it('should deploy a given datacenter', async () => {
2527
await runScript('./deploy-prod-dc.ts', 'v6', 'us1')
2628

@@ -42,22 +44,21 @@ describe.only('deploy-prod-dc', () => {
4244
])
4345
})
4446

45-
it('should only check monitors before deploying if the upload path is root', async () => {
46-
await runScript('./deploy-prod-dc.ts', 'v6', 'root', '--check-monitors')
47+
it('should deploy all minor datacenters', async () => {
48+
await runScript('./deploy-prod-dc.ts', 'v6', 'minor-dcs', '--no-check-monitors')
4749

4850
assert.deepEqual(commands, [
49-
{ command: 'node ./scripts/deploy/check-monitors.ts root' },
50-
{ command: 'node ./scripts/deploy/deploy.ts prod v6 root' },
51-
{ command: 'node ./scripts/deploy/upload-source-maps.ts v6 root' },
51+
{ command: 'node ./scripts/deploy/deploy.ts prod v6 ap1,ap2,us3,us5' },
52+
{ command: 'node ./scripts/deploy/upload-source-maps.ts v6 ap1,ap2,us3,us5' },
5253
])
5354
})
5455

55-
it('should deploy all minor datacenters', async () => {
56-
await runScript('./deploy-prod-dc.ts', 'v6', 'minor-dcs', '--no-check-monitors')
56+
it('should deploy all private regions', async () => {
57+
await runScript('./deploy-prod-dc.ts', 'v6', 'private-regions', '--no-check-monitors')
5758

5859
assert.deepEqual(commands, [
59-
{ command: 'node ./scripts/deploy/deploy.ts prod v6 us3,us5,ap1,ap2,prtest00' },
60-
{ command: 'node ./scripts/deploy/upload-source-maps.ts v6 us3,us5,ap1,ap2,prtest00' },
60+
{ command: 'node ./scripts/deploy/deploy.ts prod v6 prtest00,prtest01' },
61+
{ command: 'node ./scripts/deploy/upload-source-maps.ts v6 prtest00,prtest01' },
6162
])
6263
})
6364
})

‎scripts/deploy/lib/testHelpers.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ export function mockCommandImplementation(mockFn: Mock<(...args: any[]) => void>
6262
withCurrentWorkingDirectory: () => result,
6363
withLogs: () => result,
6464
run(): string | undefined {
65-
commands.push(commandDetail)
66-
67-
if (command.includes('aws sts assume-role')) {
65+
if (command.startsWith('aws sts assume-role')) {
6866
return JSON.stringify({
6967
Credentials: {
7068
AccessKeyId: FAKE_AWS_ENV_CREDENTIALS.AWS_ACCESS_KEY_ID,
@@ -73,6 +71,22 @@ export function mockCommandImplementation(mockFn: Mock<(...args: any[]) => void>
7371
},
7472
})
7573
}
74+
75+
if (command.startsWith('ddtool datacenters list')) {
76+
return JSON.stringify([
77+
{ name: 'ap1.prod.dog', site: 'ap1.datadoghq.com' },
78+
{ name: 'ap2.prod.dog', site: 'ap2.datadoghq.com' },
79+
{ name: 'eu1.prod.dog', site: 'datadoghq.eu' },
80+
{ name: 'us1.prod.dog', site: 'datadoghq.com' },
81+
{ name: 'us3.prod.dog', site: 'us3.datadoghq.com' },
82+
{ name: 'us5.prod.dog', site: 'us5.datadoghq.com' },
83+
{ name: 'prtest00.prod.dog', site: 'prtest00.datadoghq.com' },
84+
{ name: 'prtest01.prod.dog', site: 'prtest01.datadoghq.com' },
85+
])
86+
}
87+
88+
// don't push command details for the above mock commands
89+
commands.push(commandDetail)
7690
},
7791
}
7892
return result

‎scripts/deploy/upload-source-maps.spec.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import assert from 'node:assert/strict'
22
import path from 'node:path'
33
import { beforeEach, before, describe, it, mock } from 'node:test'
4+
import { getAllDatacenters, getSite } from '../lib/datacenter.ts'
45
import { mockModule, mockCommandImplementation, replaceChunkHashes } from './lib/testHelpers.ts'
56

6-
const MOCK_SITES = [
7-
'us1.datadoghq.com',
8-
'eu1.datadoghq.eu',
9-
'us3.datadoghq.com',
10-
'us5.datadoghq.com',
11-
'ap1.datadoghq.com',
12-
'ap2.datadoghq.com',
13-
]
147
const FAKE_API_KEY = 'FAKE_API_KEY'
158
const ENV_STAGING = {
169
DATADOG_API_KEY: FAKE_API_KEY,
@@ -57,8 +50,8 @@ describe('upload-source-maps', () => {
5750
})
5851

5952
function forEachDatacenter(callback: (site: string) => void): void {
60-
for (const site of MOCK_SITES) {
61-
callback(site)
53+
for (const datacenter of getAllDatacenters()) {
54+
callback(getSite(datacenter))
6255
}
6356
}
6457

0 commit comments

Comments
 (0)