@zukhruf/testing 0.8.18 → 0.8.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -37
- package/dist/databases/collector.d.ts +23 -20
- package/dist/databases/collector.d.ts.map +1 -1
- package/dist/databases/collector.js +9 -6
- package/dist/databases/collector.js.map +1 -1
- package/dist/databases/mysql-family-collector.d.ts +1 -6
- package/dist/databases/mysql-family-collector.d.ts.map +1 -1
- package/dist/databases/mysql-family-collector.js +12 -20
- package/dist/databases/mysql-family-collector.js.map +1 -1
- package/dist/databases/mysql-family-server.d.ts.map +1 -1
- package/dist/databases/mysql-family-server.js +2 -6
- package/dist/databases/mysql-family-server.js.map +1 -1
- package/dist/databases/postgres-collector.d.ts +1 -6
- package/dist/databases/postgres-collector.d.ts.map +1 -1
- package/dist/databases/postgres-collector.js +13 -20
- package/dist/databases/postgres-collector.js.map +1 -1
- package/dist/databases/postgres.d.ts.map +1 -1
- package/dist/databases/postgres.js +2 -3
- package/dist/databases/postgres.js.map +1 -1
- package/dist/databases/sqlserver-collector.d.ts +2 -5
- package/dist/databases/sqlserver-collector.d.ts.map +1 -1
- package/dist/databases/sqlserver-collector.js +20 -37
- package/dist/databases/sqlserver-collector.js.map +1 -1
- package/dist/databases/sqlserver.d.ts +5 -2
- package/dist/databases/sqlserver.d.ts.map +1 -1
- package/dist/databases/sqlserver.js +11 -18
- package/dist/databases/sqlserver.js.map +1 -1
- package/dist/docker/reaper.d.ts +96 -0
- package/dist/docker/reaper.d.ts.map +1 -0
- package/dist/docker/reaper.js +557 -0
- package/dist/docker/reaper.js.map +1 -0
- package/dist/docker/run-records.d.ts +3 -10
- package/dist/docker/run-records.d.ts.map +1 -1
- package/dist/docker/run-records.js +3 -14
- package/dist/docker/run-records.js.map +1 -1
- package/dist/docker/testbed.d.ts +6 -7
- package/dist/docker/testbed.d.ts.map +1 -1
- package/dist/docker/testbed.js +52 -20
- package/dist/docker/testbed.js.map +1 -1
- package/dist/scripts/docker-global-setup.d.ts +6 -1
- package/dist/scripts/docker-global-setup.d.ts.map +1 -1
- package/dist/scripts/docker-global-setup.js +42 -97
- package/dist/scripts/docker-global-setup.js.map +1 -1
- package/dist/scripts/run-cleanup.d.ts +5 -13
- package/dist/scripts/run-cleanup.d.ts.map +1 -1
- package/dist/scripts/run-cleanup.js +24 -259
- package/dist/scripts/run-cleanup.js.map +1 -1
- package/package.json +3 -3
- package/dist/scripts/docker-cleanup-worker.d.ts +0 -21
- package/dist/scripts/docker-cleanup-worker.d.ts.map +0 -1
- package/dist/scripts/docker-cleanup-worker.js +0 -31
- package/dist/scripts/docker-cleanup-worker.js.map +0 -1
package/README.md
CHANGED
|
@@ -8,24 +8,24 @@ The words in these documents have one meaning each. See the glossary in [CONTEXT
|
|
|
8
8
|
|
|
9
9
|
Each area has its own import path, so a test loads only the drivers it uses. The four drivers are optional peer dependencies: install the one an area names.
|
|
10
10
|
|
|
11
|
-
| Import | Gives
|
|
12
|
-
| ----------------------------- |
|
|
13
|
-
| `@zukhruf/testing/node` | Native `test`, `it`, `suite`, `describe` with `.each`
|
|
14
|
-
| `@zukhruf/testing/async` | `timebox`, `settleWithin`
|
|
15
|
-
| `@zukhruf/testing/docker` | `DockerTestbed`, `ServiceContainer`, `DockerDirectory`
|
|
16
|
-
| `@zukhruf/testing/postgres` | `Postgres`
|
|
17
|
-
| `@zukhruf/testing/mysql` | `Mysql`
|
|
18
|
-
| `@zukhruf/testing/mariadb` | `Mariadb`
|
|
19
|
-
| `@zukhruf/testing/sqlserver` | `SqlServer`, `SQL_SERVER_FULL_IMAGE
|
|
20
|
-
| `@zukhruf/testing/clickhouse` | `ClickHouse`
|
|
21
|
-
| `@zukhruf/testing/sqlite` | `Sqlite`
|
|
22
|
-
| `@zukhruf/testing/duckdb` | `DuckDB`
|
|
23
|
-
| `@zukhruf/testing/bigquery` | `BigQuery`
|
|
24
|
-
| `@zukhruf/testing/http` | `HttpServer`
|
|
25
|
-
| `@zukhruf/testing/streams` | `StreamHarness`
|
|
26
|
-
| `@zukhruf/testing/fs` | `TemporaryFiles`
|
|
27
|
-
| `@zukhruf/testing/msw` | `Msw`
|
|
28
|
-
| `@zukhruf/testing/preload` | `notInstalled`
|
|
11
|
+
| Import | Gives | Needs |
|
|
12
|
+
| ----------------------------- | ------------------------------------------------------ | ------------------------ |
|
|
13
|
+
| `@zukhruf/testing/node` | Native `test`, `it`, `suite`, `describe` with `.each` | |
|
|
14
|
+
| `@zukhruf/testing/async` | `timebox`, `settleWithin` | |
|
|
15
|
+
| `@zukhruf/testing/docker` | `DockerTestbed`, `ServiceContainer`, `DockerDirectory` | a Docker engine |
|
|
16
|
+
| `@zukhruf/testing/postgres` | `Postgres` | a Docker engine |
|
|
17
|
+
| `@zukhruf/testing/mysql` | `Mysql` | a Docker engine |
|
|
18
|
+
| `@zukhruf/testing/mariadb` | `Mariadb` | a Docker engine |
|
|
19
|
+
| `@zukhruf/testing/sqlserver` | `SqlServer`, `SQL_SERVER_FULL_IMAGE` | a Docker engine, `mssql` |
|
|
20
|
+
| `@zukhruf/testing/clickhouse` | `ClickHouse` | a Docker engine |
|
|
21
|
+
| `@zukhruf/testing/sqlite` | `Sqlite` | |
|
|
22
|
+
| `@zukhruf/testing/duckdb` | `DuckDB` | `@duckdb/node-api` |
|
|
23
|
+
| `@zukhruf/testing/bigquery` | `BigQuery` | `@google-cloud/bigquery` |
|
|
24
|
+
| `@zukhruf/testing/http` | `HttpServer` | |
|
|
25
|
+
| `@zukhruf/testing/streams` | `StreamHarness` | |
|
|
26
|
+
| `@zukhruf/testing/fs` | `TemporaryFiles` | |
|
|
27
|
+
| `@zukhruf/testing/msw` | `Msw` | `msw` |
|
|
28
|
+
| `@zukhruf/testing/preload` | `notInstalled` | |
|
|
29
29
|
|
|
30
30
|
## Parameterized tests
|
|
31
31
|
|
|
@@ -95,16 +95,16 @@ test('a holder in another container', async () => {
|
|
|
95
95
|
});
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
| Member | Gives
|
|
99
|
-
| ------------------------------------------------ |
|
|
100
|
-
| `start(body, { name? })` | A container this process owns. It stays after it stops, so its logs remain, until disposal removes it.
|
|
101
|
-
| `serve(body, { internalPort, name?, healthy? })` | A dedicated server whose `internalPort` answers on `127.0.0.1` of this machine. Failure or disposal removes it.
|
|
102
|
-
| `reuse(body, { internalPort, name?, healthy? })` | One server per request on the engine, shared across processes, runs and versions of this package.
|
|
103
|
-
| `run(body, { name? })` | A container that runs to completion. It gives the output and the exit code, and removes the container. A non-zero exit code does not throw.
|
|
104
|
-
| `volume()` | A named volume.
|
|
105
|
-
| `directory()` | A directory on the engine's host, for bind mounts. It has `mkdir`, `writeFile`, `readFile`, `chmod` and `symlink`.
|
|
106
|
-
| `client()` | The `@zukhruf/docker` client of the engine, for each other Engine API call, such as `info()` or `containers.find(id)`.
|
|
107
|
-
| `defaults`
|
|
98
|
+
| Member | Gives | Returns |
|
|
99
|
+
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
|
|
100
|
+
| `start(body, { name? })` | A container this process owns. It stays after it stops, so its logs remain, until disposal removes it. | `OwnedContainer` |
|
|
101
|
+
| `serve(body, { internalPort, name?, healthy? })` | A dedicated server whose `internalPort` answers on `127.0.0.1` of this machine. Failure or disposal removes it. | `ServiceContainer` |
|
|
102
|
+
| `reuse(body, { internalPort, name?, healthy? })` | One server per request on the engine, shared across processes, runs and versions of this package. | `ServiceContainer` |
|
|
103
|
+
| `run(body, { name? })` | A container that runs to completion. It gives the output and the exit code, and removes the container. A non-zero exit code does not throw. | `ExecResult` |
|
|
104
|
+
| `volume()` | A named volume. | `OwnedVolume` |
|
|
105
|
+
| `directory()` | A directory on the engine's host, for bind mounts. It has `mkdir`, `writeFile`, `readFile`, `chmod` and `symlink`. | `DockerDirectory` |
|
|
106
|
+
| `client()` | The `@zukhruf/docker` client of the engine, for each other Engine API call, such as `info()` or `containers.find(id)`. | `Docker` (from `@zukhruf/docker`) |
|
|
107
|
+
| `defaults()` | The run's labels and the default resources, in the shape of a body: `{ Labels, HostConfig: { Memory, NanoCpus } }`. In a run, it holds the run's reaper first. | |
|
|
108
108
|
|
|
109
109
|
The `body` is the body of a container create in the Engine API: `EngineApi.ContainerCreateRequest` of `@zukhruf/docker`. Write it with the fields of the Engine API, for example `Image`, `Cmd`, `Entrypoint`, `Env` (strings `KEY=value`), `Hostname`, `Labels`, and in `HostConfig`: `Binds`, `Tmpfs`, `Memory`, `NanoCpus`, `IpcMode` and `MemorySwappiness`. The testbed adds these values to each body before it creates the container:
|
|
110
110
|
|
|
@@ -124,9 +124,9 @@ A dedicated server is not ready when `healthy` throws, or when its container exi
|
|
|
124
124
|
|
|
125
125
|
`reuse(body, options)` finds the server for this request, or creates it. The request is the body after the testbed adds its defaults and the published port, and the `internalPort`. The order of the keys and the order of the `Env` entries do not select a different server. Docker reserves the name atomically, so concurrent processes attach to the same container. Different images, passwords, environments or labels select separate servers. The version of `@zukhruf/testing` does not: projects on different versions that send the same request share one server. A readiness failure leaves the shared server running for diagnosis. Dispose a reused server only after all its users finish: disposal stops it for every caller.
|
|
126
126
|
|
|
127
|
-
The name of a shared server is `zukhruf-testing-<fingerprint>`, and its label `dev.zukhruf.testing.server` holds the fingerprint. The fingerprint is a hash of the request. At the end of a run that used Docker, the
|
|
127
|
+
The name of a shared server is `zukhruf-testing-<fingerprint>`, and its label `dev.zukhruf.testing.server` holds the fingerprint. The fingerprint is a hash of the request. At the end of a run that used Docker, the run's reaper removes each shared server on its engine that is older than its time to live (TTL) of 7 days, from its `Created` time. It keeps a server while a test process uses it ([ADR 0019](./docs/adr/0019-a-shared-servers-name-comes-from-its-request-and-the-global-teardown-removes-it-after-a-ttl.md)). Each test process that calls `reuse()` holds a process lease for each shared server that it uses: a small `busybox` container that runs `cat` on the input of an attach. When the process exits, also when it is killed, the attach closes and the engine removes the lease. The attach does not keep the process running. Before the reaper removes a server, it takes the sweep lease of that server, and then it looks for a process lease of that server. A test process takes its process lease, and then it looks for the sweep lease of its server. When that sweep lease exists, `reuse()` waits until the sweep ends, and then finds or creates its server ([ADR 0014](./docs/adr/0014-a-test-process-holds-a-process-lease-and-the-global-teardown-keeps-the-shared-servers-of-a-version-that-has-one.md)).
|
|
128
128
|
|
|
129
|
-
The
|
|
129
|
+
The reaper checks the servers only at the end of a run that used Docker. An engine that no run uses keeps its servers.
|
|
130
130
|
|
|
131
131
|
When you change your own body, the old server stays until its TTL ends. A newer image behind the same tag does not change the request. To use the newer image now, stop the server:
|
|
132
132
|
|
|
@@ -168,21 +168,31 @@ Then give the file to `node --test`. The value is a path relative to the working
|
|
|
168
168
|
node --test --test-force-exit --test-global-setup=src/testing/docker-global-setup.ts "src/**/*.test.ts"
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
The global setup sets `ZUKHRUF_TESTING_RUN_ID` and `ZUKHRUF_TESTING_RUN_DIR` for the test processes. A `DockerTestbed` reads them from its `environment` and labels what it creates with the run. It records SSH forwards and host directories in the run's directory. It also writes a process record for its test process, and for each SSH command that it starts, while that command runs.
|
|
171
|
+
The global setup sets `ZUKHRUF_TESTING_RUN_ID` and `ZUKHRUF_TESTING_RUN_DIR` for the test processes. A `DockerTestbed` reads them from its `environment` and labels what it creates with the run. It records SSH forwards and host directories in the run's directory. It also writes a process record for its test process, and for each SSH command that it starts, while that command runs. In a run, `database()` puts the run's id in the name of each database that it creates on a shared server: `test_<run id>_<16 hex>`.
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
Before a test process creates anything on an engine, its `DockerTestbed` holds the run's reaper there: a container of the image `docker:28.5.2-cli` with the engine's socket mounted, one for each run on each engine ([ADR 0020](./docs/adr/0020-a-reaper-container-removes-a-runs-engine-objects-when-the-attach-that-holds-it-closes-and-recovery-keeps-the-local-records.md)). The first test process creates it. Each test process holds it with one `cat` exec whose connection ends when the process exits, also when it is killed. The hold does not keep the process running. A hold that ends while its process lives, for example at a break of the SSH connection, is taken again at once. About 2 s after the last test process of the run ended, the reaper:
|
|
174
174
|
|
|
175
|
-
|
|
175
|
+
1. removes the labeled containers with their anonymous volumes, and the labeled volumes. It never removes a shared server;
|
|
176
|
+
2. drops, on each running shared server of `Postgres`, `Mysql`, `Mariadb` and `SqlServer`, the databases whose name has the run's id, with the client in the server's image ([ADR 0011](./docs/adr/0011-the-run-id-in-a-databases-name-is-its-owner-reference-and-one-collector-for-each-kind-drops-a-dead-runs-databases.md));
|
|
177
|
+
3. does this again 5 times, 1 s apart, for a create that the engine finished after its test process died;
|
|
178
|
+
4. removes each shared server that is older than its TTL, unless a test process holds a process lease for it (see [Shared servers](#shared-servers));
|
|
179
|
+
5. exits, and the engine removes it.
|
|
176
180
|
|
|
177
|
-
|
|
181
|
+
A test process that comes during the 2 s stops the countdown, and the reaper waits for its end. From step 1 on, the reaper is closed: a test process that comes then waits until the engine removed it, and holds the next reaper of the run. Each request of the reaper to the engine has a time limit of 10 s, and a removal is tried 10 more times. A shared server that does not answer a list or a drop in that time keeps the run's databases. The test processes and the global teardown never wait for the reaper.
|
|
182
|
+
|
|
183
|
+
The global teardown is synchronous, because Node does not wait for an asynchronous teardown under `--test-force-exit`, and it makes no engine call. It removes the recorded paths. It deletes the run's records only when the run has no process record. Otherwise it keeps them, because it cannot see whether the reaper acted: a reaper can be killed before its passes, for example at a restart of the engine.
|
|
184
|
+
|
|
185
|
+
If the teardown fails, it prints the error, keeps the run's records, and sets exit code 1. The next run on the same engine recovers each run whose records stay, from any project of this user. This is recovery. It removes the recorded paths, and then asks the engine. While the run's reaper exists, recovery leaves the run to it and keeps the records. When the reaper is gone but a container, a volume or a database of the run is left, recovery starts a new reaper of the run and keeps the records. When the reaper is gone and nothing of the run is left, recovery deletes the records. Thus a run's records go at the first recovery after its reaper ended. Recovery does not touch a run while its runner or one of its recorded processes lives. A reaper that a killed process left `created` is started by the next reaper of another run on the same engine. The records are in `$XDG_STATE_HOME/zukhruf-testing/docker-runs` (`~/.local/state/zukhruf-testing/docker-runs` by default). Do not delete a record to hide a cleanup failure.
|
|
186
|
+
|
|
187
|
+
The global setup selects the engine as the Docker CLI does, through `@zukhruf/docker`, so the Docker CLI is not necessary. It calls the engine only when a dead run on that engine has process records, which each run that used the engine has until a recovery deletes them.
|
|
178
188
|
|
|
179
189
|
On an SSH engine, run one test file at a time with `--test-concurrency=1` if the engine cannot take more. An SSH forward runs `cat` in a remote shell, so the SSH user needs a shell on the engine's host. The forward ends when the process that opened it ends, also when that process is killed.
|
|
180
190
|
|
|
181
|
-
Another Docker client can create containers for the run, for example a sandbox launcher. Give it `testbed.defaults`: its `Labels` are the run's labels, and its `HostConfig` has the default `Memory` and `NanoCpus`. A client that takes the Engine API body uses them as they are. Map them to the options of a client that has its own options.
|
|
191
|
+
Another Docker client can create containers for the run, for example a sandbox launcher. Give it `await testbed.defaults()`: its `Labels` are the run's labels, and its `HostConfig` has the default `Memory` and `NanoCpus`. A client that takes the Engine API body uses them as they are. Map them to the options of a client that has its own options. In a run, `defaults()` writes a process record for this process and holds the run's reaper on the testbed's engine before it gives the labels, as a create does. Thus the reaper removes what the other client created with them after the run's last test process ends. Outside a run, it makes no engine call.
|
|
182
192
|
|
|
183
193
|
## Databases
|
|
184
194
|
|
|
185
|
-
`Postgres`, `Mysql`, `Mariadb`, `SqlServer` and `ClickHouse` take the `environment`, such as `process.env`. The environment selects the engine and the run. Each instance makes its own `DockerTestbed` from it. Each `database()` call creates a fresh database on a shared server; disposal drops it. In a run, the name of the database has the run's id. When a test process is killed before its disposal, or a drop in disposal fails, the
|
|
195
|
+
`Postgres`, `Mysql`, `Mariadb`, `SqlServer` and `ClickHouse` take the `environment`, such as `process.env`. The environment selects the engine and the run. Each instance makes its own `DockerTestbed` from it. Each `database()` call creates a fresh database on a shared server; disposal drops it. In a run, the name of the database has the run's id. When a test process is killed before its disposal, or a drop in disposal fails, the run's reaper drops the database (see [A killed run](#a-killed-run)). Outside a run, only disposal drops it. `start()` creates a dedicated server; disposal stops it.
|
|
186
196
|
|
|
187
197
|
```ts
|
|
188
198
|
import { Postgres } from '@zukhruf/testing/postgres';
|
|
@@ -195,7 +205,7 @@ test('stores a record', async () => {
|
|
|
195
205
|
});
|
|
196
206
|
```
|
|
197
207
|
|
|
198
|
-
The handle has `connectionString`, `host`, `port`, `user`, `password`, `database`, `image` and `containerId`. `Mysql` and `Mariadb` handles also have `query(sql)`. Without an image, `Mysql` runs `mysql:lts` and `Mariadb` runs `mariadb:lts`. MariaDB 11 and later have no `mysql` client, so use `Mariadb` for a MariaDB image. A `Mariadb` connection string starts with `mariadb://`, because the `mariadb` driver accepts no other scheme. Without an image, `SqlServer`
|
|
208
|
+
The handle has `connectionString`, `host`, `port`, `user`, `password`, `database`, `image` and `containerId`. `Mysql` and `Mariadb` handles also have `query(sql)`. Without an image, `Mysql` runs `mysql:lts` and `Mariadb` runs `mariadb:lts`. MariaDB 11 and later have no `mysql` client, so use `Mariadb` for a MariaDB image. A `Mariadb` connection string starts with `mariadb://`, because the `mariadb` driver accepts no other scheme. Without an image, `SqlServer` runs SQL Server 2022 (`SQL_SERVER_FULL_IMAGE`) on every engine. Microsoft builds it only for amd64, so an ARM engine runs it under emulation. `ClickHouse` takes an explicit `image`, and its `start()` gives a `ServiceContainer` of a dedicated server, so a test can create server-wide users and functions.
|
|
199
209
|
|
|
200
210
|
`Sqlite` creates a file-backed database in a temporary directory, with a native `DatabaseSync` connection. Disposal closes the connection and removes the directory, including WAL files. `writeLock(path, durationMs)` holds a write lock from another process, which releases it after `durationMs`, even while the caller blocks in a synchronous write.
|
|
201
211
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DockerHost } from '../docker/host.ts';
|
|
1
|
+
import type { Container } from '@zukhruf/docker';
|
|
3
2
|
/** The kind of a database fixture's shared server: it names the collector of the server. */
|
|
4
3
|
export declare const KIND_LABEL = "dev.zukhruf.testing.kind";
|
|
5
4
|
export type Kind = 'postgres' | 'mysql' | 'mariadb' | 'sqlserver';
|
|
@@ -9,25 +8,29 @@ export type Kind = 'postgres' | 'mysql' | 'mariadb' | 'sqlserver';
|
|
|
9
8
|
*/
|
|
10
9
|
export declare const databaseName: (id: string | undefined) => string;
|
|
11
10
|
/**
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* The extended regular expression of the names of the databases of the run
|
|
12
|
+
* whose id without hyphens is `runHex`. `_` is a wildcard of SQL's LIKE, so
|
|
13
|
+
* only this exact pattern proves a run's database.
|
|
15
14
|
*/
|
|
16
|
-
export
|
|
17
|
-
readonly kind: Kind;
|
|
18
|
-
/**
|
|
19
|
-
* The running shared server `container`, with the credentials of
|
|
20
|
-
* `environment`, its `Config.Env`. Disposal closes what it opened.
|
|
21
|
-
*/
|
|
22
|
-
open(container: Container, environment: Record<string, string>, host: DockerHost): Promise<Server & AsyncDisposable>;
|
|
23
|
-
/** Each database whose name starts with `test`, a superset of a run's. */
|
|
24
|
-
list(server: Server, cancel: CancelOptions): Promise<string[]>;
|
|
25
|
-
/** Drops the database `name` if it exists. */
|
|
26
|
-
drop(server: Server, name: string, cancel: CancelOptions): Promise<void>;
|
|
27
|
-
}
|
|
15
|
+
export declare const ownedNames: (runHex: string) => string;
|
|
28
16
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
17
|
+
* The databases of one server kind, through the client in the server's
|
|
18
|
+
* image. Disposal and the reaper (ADR 0020) both run its command and SQL.
|
|
31
19
|
*/
|
|
32
|
-
export
|
|
20
|
+
export interface Collector {
|
|
21
|
+
readonly kind: Kind;
|
|
22
|
+
/** The variable of the server's `Config.Env` that holds the client's credential, and the credential without it. */
|
|
23
|
+
readonly credential: {
|
|
24
|
+
variable: string;
|
|
25
|
+
fallback?: string;
|
|
26
|
+
};
|
|
27
|
+
/** The command in the server's container that runs `sql` with `credential`, and prints one value of each row a line. */
|
|
28
|
+
command(credential: string, sql: string): string[];
|
|
29
|
+
/** The SQL that lists each database whose name starts with `test`, a superset of a run's. */
|
|
30
|
+
readonly list: string;
|
|
31
|
+
/** The SQL that drops the database `name` if it exists. */
|
|
32
|
+
drop(name: string): string;
|
|
33
|
+
}
|
|
34
|
+
/** Drops the database `name` in the server `container` with the client of `collector`. */
|
|
35
|
+
export declare function dropDatabase(collector: Collector, container: Container, credential: string, name: string): Promise<void>;
|
|
33
36
|
//# sourceMappingURL=collector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../src/databases/collector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../src/databases/collector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,4FAA4F;AAC5F,eAAO,MAAM,UAAU,6BAA6B,CAAC;AAErD,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAIlE;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,GAAG,SAAS,KAAG,MAGrB,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,MACX,CAAC;AAElC;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,mHAAmH;IACnH,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7D,wHAAwH;IACxH,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACnD,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,0FAA0F;AAC1F,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAKf"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { succeeded } from "./succeeded.js";
|
|
2
3
|
/** The kind of a database fixture's shared server: it names the collector of the server. */
|
|
3
4
|
export const KIND_LABEL = 'dev.zukhruf.testing.kind';
|
|
4
5
|
const hex = (runId) => runId.replaceAll('-', '');
|
|
@@ -10,11 +11,13 @@ export const databaseName = (id) => id
|
|
|
10
11
|
? `test_${hex(id)}_${randomBytes(8).toHex()}`
|
|
11
12
|
: `test_${hex(randomUUID())}`;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* The extended regular expression of the names of the databases of the run
|
|
15
|
+
* whose id without hyphens is `runHex`. `_` is a wildcard of SQL's LIKE, so
|
|
16
|
+
* only this exact pattern proves a run's database.
|
|
15
17
|
*/
|
|
16
|
-
export const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
export const ownedNames = (runHex) => `^test_${runHex}_[0-9a-f]{16}$`;
|
|
19
|
+
/** Drops the database `name` in the server `container` with the client of `collector`. */
|
|
20
|
+
export async function dropDatabase(collector, container, credential, name) {
|
|
21
|
+
await succeeded(container, collector.command(credential, collector.drop(name)));
|
|
22
|
+
}
|
|
20
23
|
//# sourceMappingURL=collector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.js","sourceRoot":"","sources":["../../src/databases/collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"collector.js","sourceRoot":"","sources":["../../src/databases/collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAIrD,MAAM,GAAG,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAsB,EAAU,EAAE,CAC7D,EAAE;IACA,CAAC,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;IAC7C,CAAC,CAAC,QAAQ,GAAG,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAU,EAAE,CACnD,SAAS,MAAM,gBAAgB,CAAC;AAkBlC,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,SAAoB,EACpB,SAAoB,EACpB,UAAkB,EAClB,IAAY;IAEZ,MAAM,SAAS,CACb,SAAS,EACT,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CACpD,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { Container } from '@zukhruf/docker';
|
|
2
1
|
import type { Collector } from './collector.ts';
|
|
3
|
-
export interface MysqlFamilyServer {
|
|
4
|
-
container: Container;
|
|
5
|
-
password: string;
|
|
6
|
-
}
|
|
7
2
|
/** The image creates only root, from the root password in its environment. */
|
|
8
3
|
export declare const user = "root";
|
|
9
|
-
export interface MysqlFamilyCollector extends Collector
|
|
4
|
+
export interface MysqlFamilyCollector extends Collector {
|
|
10
5
|
/** The client in the image. */
|
|
11
6
|
readonly client: string;
|
|
12
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-family-collector.d.ts","sourceRoot":"","sources":["../../src/databases/mysql-family-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mysql-family-collector.d.ts","sourceRoot":"","sources":["../../src/databases/mysql-family-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAQ,MAAM,gBAAgB,CAAC;AAEtD,8EAA8E;AAC9E,eAAO,MAAM,IAAI,SAAS,CAAC;AAE3B,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AA0BD,eAAO,MAAM,KAAK,sBAAuD,CAAC;AAC1E,oEAAoE;AACpE,eAAO,MAAM,OAAO,sBAInB,CAAC"}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
import { succeeded } from "./succeeded.js";
|
|
2
1
|
/** The image creates only root, from the root password in its environment. */
|
|
3
2
|
export const user = 'root';
|
|
4
3
|
/** Runs the image's client in the server's container. */
|
|
5
4
|
function mysqlFamily(kind, client, passwordVariable) {
|
|
6
|
-
const execute = ({ container, password }, args, cancel) => succeeded(container, [client, `-u${user}`, `-p${password}`, ...args], cancel);
|
|
7
5
|
return {
|
|
8
6
|
kind,
|
|
9
7
|
client,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
], cancel);
|
|
23
|
-
return stdout.split('\n').filter(Boolean);
|
|
24
|
-
},
|
|
25
|
-
async drop(server, name, cancel) {
|
|
26
|
-
await execute(server, ['--execute', `DROP DATABASE IF EXISTS \`${name}\``], cancel);
|
|
27
|
-
},
|
|
8
|
+
credential: { variable: passwordVariable },
|
|
9
|
+
command: (password, sql) => [
|
|
10
|
+
client,
|
|
11
|
+
`-u${user}`,
|
|
12
|
+
`-p${password}`,
|
|
13
|
+
'--batch',
|
|
14
|
+
'--skip-column-names',
|
|
15
|
+
'--execute',
|
|
16
|
+
sql,
|
|
17
|
+
],
|
|
18
|
+
list: "SHOW DATABASES LIKE 'test%'",
|
|
19
|
+
drop: (name) => `DROP DATABASE IF EXISTS \`${name}\``,
|
|
28
20
|
};
|
|
29
21
|
}
|
|
30
22
|
export const mysql = mysqlFamily('mysql', 'mysql', 'MYSQL_ROOT_PASSWORD');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-family-collector.js","sourceRoot":"","sources":["../../src/databases/mysql-family-collector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mysql-family-collector.js","sourceRoot":"","sources":["../../src/databases/mysql-family-collector.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAO3B,yDAAyD;AACzD,SAAS,WAAW,CAClB,IAAU,EACV,MAAc,EACd,gBAAwB;IAExB,OAAO;QACL,IAAI;QACJ,MAAM;QACN,UAAU,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;QAC1C,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC;YAC1B,MAAM;YACN,KAAK,IAAI,EAAE;YACX,KAAK,QAAQ,EAAE;YACf,SAAS;YACT,qBAAqB;YACrB,WAAW;YACX,GAAG;SACJ;QACD,IAAI,EAAE,6BAA6B;QACnC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,6BAA6B,IAAI,IAAI;KACtD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;AAC1E,oEAAoE;AACpE,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAChC,SAAS,EACT,SAAS,EACT,uBAAuB,CACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-family-server.d.ts","sourceRoot":"","sources":["../../src/databases/mysql-family-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,oBAAoB,EAAQ,MAAM,6BAA6B,CAAC;AAG9E,MAAM,WAAW,mBAAoB,SAAQ,QAAQ;IACnD,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;CAClE;AAED;;;;;;GAMG;AACH,8BAAsB,iBAAiB;;IAKrC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IAC5D,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,WAAW,CAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEb,EACV,WAAW,EACX,KAAK,EACL,QAAyB,EACzB,QAAgB,EAChB,MAAM,GACP,EAAE,eAAe,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAMtC,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"mysql-family-server.d.ts","sourceRoot":"","sources":["../../src/databases/mysql-family-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,oBAAoB,EAAQ,MAAM,6BAA6B,CAAC;AAG9E,MAAM,WAAW,mBAAoB,SAAQ,QAAQ;IACnD,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;CAClE;AAED;;;;;;GAMG;AACH,8BAAsB,iBAAiB;;IAKrC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IAC5D,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,WAAW,CAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEb,EACV,WAAW,EACX,KAAK,EACL,QAAyB,EACzB,QAAgB,EAChB,MAAM,GACP,EAAE,eAAe,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAMtC,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAsB9C,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;CAkH5C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { timebox } from "../async/timebox.js";
|
|
2
2
|
import { readRun } from "../docker/run-records.js";
|
|
3
3
|
import { DockerTestbed } from "../docker/testbed.js";
|
|
4
|
-
import { KIND_LABEL, databaseName } from "./collector.js";
|
|
4
|
+
import { KIND_LABEL, databaseName, dropDatabase } from "./collector.js";
|
|
5
5
|
import { user } from "./mysql-family-collector.js";
|
|
6
6
|
import { succeeded } from "./succeeded.js";
|
|
7
7
|
/**
|
|
@@ -24,10 +24,6 @@ export class MysqlFamilyServer {
|
|
|
24
24
|
async database() {
|
|
25
25
|
const container = await this.#acquire('app', 'reuse');
|
|
26
26
|
const database = databaseName(this.#runId);
|
|
27
|
-
const server = {
|
|
28
|
-
container: container.container,
|
|
29
|
-
password: this.#options.password,
|
|
30
|
-
};
|
|
31
27
|
try {
|
|
32
28
|
await this.#sql(container, `CREATE DATABASE \`${database}\``);
|
|
33
29
|
}
|
|
@@ -36,7 +32,7 @@ export class MysqlFamilyServer {
|
|
|
36
32
|
throw error;
|
|
37
33
|
}
|
|
38
34
|
return this.#handle(container, database, async () => {
|
|
39
|
-
await this.collector.
|
|
35
|
+
await dropDatabase(this.collector, container.container, this.#options.password, database).catch(() => {
|
|
40
36
|
/* Best-effort: the run's cleanup drops a database that disposal left. */
|
|
41
37
|
});
|
|
42
38
|
await container.disconnect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql-family-server.js","sourceRoot":"","sources":["../../src/databases/mysql-family-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"mysql-family-server.js","sourceRoot":"","sources":["../../src/databases/mysql-family-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAA6B,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM3C;;;;;;GAMG;AACH,MAAM,OAAgB,iBAAiB;IAC5B,OAAO,CAAgB;IACvB,MAAM,CAAqB;IAC3B,QAAQ,CAAC;IASlB,YAAY,EACV,WAAW,EACX,KAAK,EACL,QAAQ,GAAG,cAAc,EACzB,QAA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8E;QAC9E,OAAO,OAAO,CACZ,GAAG,EAAE,CACH,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,MAAM;YACrB,IAAI;YACJ,WAAW;YACX,KAAK,IAAI,EAAE;YACX,KAAK,QAAQ,EAAE;YACf,WAAW;YACX,UAAU;SACX,CAAC,EACJ,EAAE,YAAY,EAAE,MAAM,EAAE,CACzB,CAAC;IACJ,CAAC;IAED,OAAO,CACL,SAA2B,EAC3B,QAAgB,EAChB,OAA4B;QAE5B,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC1C,OAAO;YACL,gBAAgB,EAAE,GAAG,IAAI,CAAC,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,IAAI,QAAQ,EAAE;YACxG,KAAK;YACL,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE;YACnC,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC;YACrD,OAAO;YACP,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type { Container } from '@zukhruf/docker';
|
|
2
1
|
import type { Collector } from './collector.ts';
|
|
3
|
-
export interface PostgresServer {
|
|
4
|
-
container: Container;
|
|
5
|
-
user: string;
|
|
6
|
-
}
|
|
7
2
|
/** Runs `psql` in the server's container. */
|
|
8
|
-
export declare const postgres: Collector
|
|
3
|
+
export declare const postgres: Collector;
|
|
9
4
|
//# sourceMappingURL=postgres-collector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-collector.d.ts","sourceRoot":"","sources":["../../src/databases/postgres-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"postgres-collector.d.ts","sourceRoot":"","sources":["../../src/databases/postgres-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,EAAE,SAetB,CAAC"}
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { succeeded } from "./succeeded.js";
|
|
2
|
-
const psql = ({ container, user }, args, cancel) => succeeded(container, ['psql', '-U', user, '-d', 'postgres', ...args], cancel);
|
|
3
1
|
/** Runs `psql` in the server's container. */
|
|
4
2
|
export const postgres = {
|
|
5
3
|
kind: 'postgres',
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return stdout.split('\n').filter(Boolean);
|
|
20
|
-
},
|
|
21
|
-
async drop(server, name, cancel) {
|
|
22
|
-
await psql(server, ['-c', `DROP DATABASE IF EXISTS "${name}" WITH (FORCE)`], cancel);
|
|
23
|
-
},
|
|
4
|
+
credential: { variable: 'POSTGRES_USER', fallback: 'postgres' },
|
|
5
|
+
command: (user, sql) => [
|
|
6
|
+
'psql',
|
|
7
|
+
'-U',
|
|
8
|
+
user,
|
|
9
|
+
'-d',
|
|
10
|
+
'postgres',
|
|
11
|
+
'-At',
|
|
12
|
+
'-c',
|
|
13
|
+
sql,
|
|
14
|
+
],
|
|
15
|
+
list: "SELECT datname FROM pg_database WHERE datname LIKE 'test%'",
|
|
16
|
+
drop: (name) => `DROP DATABASE IF EXISTS "${name}" WITH (FORCE)`,
|
|
24
17
|
};
|
|
25
18
|
//# sourceMappingURL=postgres-collector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-collector.js","sourceRoot":"","sources":["../../src/databases/postgres-collector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postgres-collector.js","sourceRoot":"","sources":["../../src/databases/postgres-collector.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,MAAM,CAAC,MAAM,QAAQ,GAAc;IACjC,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE;IAC/D,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;QACtB,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,UAAU;QACV,KAAK;QACL,IAAI;QACJ,GAAG;KACJ;IACD,IAAI,EAAE,4DAA4D;IAClE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,4BAA4B,IAAI,gBAAgB;CACjE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/databases/postgres.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAI/D,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qFAAqF;AACrF,qBAAa,QAAQ;;gBAKP,EACV,WAAW,EACX,KAA4B,EAC5B,QAAyB,EACzB,QAAmB,EACnB,IAAiB,EACjB,MAAM,GACP,EAAE,eAAe;IAMlB,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/databases/postgres.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAI/D,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qFAAqF;AACrF,qBAAa,QAAQ;;gBAKP,EACV,WAAW,EACX,KAA4B,EAC5B,QAAyB,EACzB,QAAmB,EACnB,IAAiB,EACjB,MAAM,GACP,EAAE,eAAe;IAMlB,mEAAmE;IAC7D,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAsBnC,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;CA2FjC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { timebox } from "../async/timebox.js";
|
|
2
2
|
import { readRun } from "../docker/run-records.js";
|
|
3
3
|
import { DockerTestbed } from "../docker/testbed.js";
|
|
4
|
-
import { KIND_LABEL, databaseName } from "./collector.js";
|
|
4
|
+
import { KIND_LABEL, databaseName, dropDatabase } from "./collector.js";
|
|
5
5
|
import { postgres } from "./postgres-collector.js";
|
|
6
6
|
import { succeeded } from "./succeeded.js";
|
|
7
7
|
/** PostgreSQL test configuration. Each acquisition returns an independent handle. */
|
|
@@ -18,7 +18,6 @@ export class Postgres {
|
|
|
18
18
|
async database() {
|
|
19
19
|
const container = await this.#acquire('postgres', 'reuse');
|
|
20
20
|
const database = databaseName(this.#runId);
|
|
21
|
-
const server = { container: container.container, user: this.#options.user };
|
|
22
21
|
try {
|
|
23
22
|
await this.#sql(container, `CREATE DATABASE ${database}`);
|
|
24
23
|
}
|
|
@@ -27,7 +26,7 @@ export class Postgres {
|
|
|
27
26
|
throw error;
|
|
28
27
|
}
|
|
29
28
|
return this.#handle(container, database, async () => {
|
|
30
|
-
await postgres.
|
|
29
|
+
await dropDatabase(postgres, container.container, this.#options.user, database).catch(() => {
|
|
31
30
|
/* Best-effort: the run's cleanup drops a database that disposal left. */
|
|
32
31
|
});
|
|
33
32
|
await container.disconnect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/databases/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../../src/databases/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQ3C,qFAAqF;AACrF,MAAM,OAAO,QAAQ;IACV,OAAO,CAAgB;IACvB,MAAM,CAAqB;IAC3B,QAAQ,CAAC;IAElB,YAAY,EACV,WAAW,EACX,KAAK,GAAG,oBAAoB,EAC5B,QAAQ,GAAG,cAAc,EACzB,QAAQ,GAAG,QAAQ,EACnB,IAAI,GAAG,UAAU,EACjB,MAAM,GACU;QAChB,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,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;gBACR,IAAI;gBACJ,UAAU;aACX,CAAC,CAAC;QACL,CAAC,EACD,EAAE,YAAY,EAAE,MAAM,EAAE,CACzB,CAAC;IACJ,CAAC;IAED,OAAO,CACL,SAA2B,EAC3B,QAAgB,EAChB,OAA4B;QAE5B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChD,OAAO;YACL,gBAAgB,EAAE,gBAAgB,IAAI,IAAI,QAAQ,IAAI,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,IAAI,QAAQ,EAAE;YACpG,KAAK;YACL,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,EAAE;YACnC,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,IAAI,EAAE,SAAS,CAAC,IAAI;YACpB,OAAO;YACP,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -5,9 +5,6 @@ export interface SqlServerServer {
|
|
|
5
5
|
password: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const connectionString: ({ host, port, password }: SqlServerServer, database: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
* has no `sqlcmd` to exec.
|
|
11
|
-
*/
|
|
12
|
-
export declare const sqlserver: Collector<SqlServerServer>;
|
|
8
|
+
/** Runs `sqlcmd` of the `mssql/server` image in the server's container (ADR 0020, item 8). */
|
|
9
|
+
export declare const sqlserver: Collector;
|
|
13
10
|
//# sourceMappingURL=sqlserver-collector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlserver-collector.d.ts","sourceRoot":"","sources":["../../src/databases/sqlserver-collector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlserver-collector.d.ts","sourceRoot":"","sources":["../../src/databases/sqlserver-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,gBAAgB,GAC3B,0BAA0B,eAAe,EACzC,UAAU,MAAM,KACf,MACuH,CAAC;AAE3H,8FAA8F;AAC9F,eAAO,MAAM,SAAS,EAAE,SAsBvB,CAAC"}
|