-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathping.test.ts
More file actions
44 lines (36 loc) · 1.2 KB
/
ping.test.ts
File metadata and controls
44 lines (36 loc) · 1.2 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
import assert from 'node:assert/strict';
import { afterEach, beforeEach, suite, test } from 'node:test';
import { Client } from './Client.js';
import { Container } from './Container.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
suite('ping', { timeout: 30_000 }, () => {
let container: Container;
beforeEach(async () => {
const imageVersion = getImageVersionFromDockerfile();
container = new Container().withImageTag(imageVersion);
await container.start();
});
afterEach(async () => {
await container.stop();
});
test('does not throw an error if the server is reachable.', async (): Promise<void> => {
const client = container.getClient();
// Should not throw.
await client.ping();
});
test('throws an error if the server is not reachable.', async (): Promise<void> => {
const port = container.getMappedPort();
const apiToken = container.getApiToken();
const client = new Client(new URL(`http://non-existent-host:${port}/`), apiToken);
await assert.rejects(
async () => {
await client.ping();
},
error => {
assert.ok(error instanceof Error);
assert.equal(error.message, 'fetch failed');
return true;
},
);
});
});