-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapphost.test.ts
More file actions
90 lines (75 loc) · 2.06 KB
/
Copy pathapphost.test.ts
File metadata and controls
90 lines (75 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
type ChildProcess,
spawn,
spawnSync,
} from 'node:child_process';
import {
GetParameterCommand,
PutParameterCommand,
SSMClient,
} from '@aws-sdk/client-ssm';
import { afterAll, beforeAll, expect, it } from 'vitest';
const LOCALSTACK_URL = 'http://localhost:4566';
let aspire: ChildProcess;
let ssm: SSMClient;
beforeAll(async () => {
aspire = spawn('aspire', ['run'], {
cwd: import.meta.dirname,
stdio: 'ignore',
shell: process.platform === 'win32',
});
await waitForLocalStack(`${LOCALSTACK_URL}/_localstack/health`, 180_000);
ssm = new SSMClient({
endpoint: LOCALSTACK_URL,
region: 'us-east-1',
credentials: { accessKeyId: 'test', secretAccessKey: 'test' },
});
}, 240_000);
afterAll(() => {
if (aspire?.pid === undefined) {
return;
}
if (process.platform === 'win32') {
spawnSync('taskkill', ['/pid', String(aspire.pid), '/t', '/f']);
} else {
aspire.kill('SIGINT');
}
});
it('Should_ReportSsmService_When_AspireStartsLocalStack', async () => {
// Act
const response = await fetch(`${LOCALSTACK_URL}/_localstack/health`);
const health = await response.json();
// Assert
expect(['available', 'running']).toContain(health.services.ssm);
});
it('Should_RoundTripSecureString_When_AspireInjectsResolvedToken', async () => {
// Arrange
await ssm.send(
new PutParameterCommand({
Name: '/demo/secret',
Value: 'hunter2',
Type: 'SecureString',
Overwrite: true,
}),
);
// Act
const actual = await ssm.send(
new GetParameterCommand({ Name: '/demo/secret', WithDecryption: true }),
);
// Assert
expect(actual.Parameter?.Value).toBe('hunter2');
});
async function waitForLocalStack(
url: string,
timeoutMs: number,
): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const response = await fetch(url).catch(() => null);
if (response?.ok) {
return;
}
await new Promise((resolve) => setTimeout(resolve, 2_000));
}
throw new Error(`LocalStack did not become ready within ${timeoutMs} ms`);
}