feat: use deno port generator
This commit is contained in:
@@ -1,10 +1,3 @@
|
|||||||
import delay from "delay";
|
|
||||||
import getPort from "port";
|
|
||||||
import psql, { type Sql } from "postgres";
|
|
||||||
|
|
||||||
import type { Container } from "../docker/libraries/container.ts";
|
|
||||||
import { docker } from "../mod.ts";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module
|
* @module
|
||||||
*
|
*
|
||||||
@@ -24,6 +17,14 @@ import { docker } from "../mod.ts";
|
|||||||
* await container.stop();
|
* await container.stop();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import delay from "delay";
|
||||||
|
import getPort from "port";
|
||||||
|
import psql, { type Sql } from "postgres";
|
||||||
|
|
||||||
|
import type { Container } from "../docker/libraries/container.ts";
|
||||||
|
import { docker } from "../mod.ts";
|
||||||
|
|
||||||
export class PostgresTestContainer {
|
export class PostgresTestContainer {
|
||||||
private constructor(
|
private constructor(
|
||||||
readonly container: Container,
|
readonly container: Container,
|
||||||
@@ -68,7 +69,7 @@ export class PostgresTestContainer {
|
|||||||
* @param config - Options for the Postgres container.
|
* @param config - Options for the Postgres container.
|
||||||
*/
|
*/
|
||||||
static async start(image: string, config: Partial<Config> = {}): Promise<PostgresTestContainer> {
|
static async start(image: string, config: Partial<Config> = {}): Promise<PostgresTestContainer> {
|
||||||
const port = await getPort();
|
const port = getPort();
|
||||||
if (port === undefined) {
|
if (port === undefined) {
|
||||||
throw new Error("Unable to assign to a random port");
|
throw new Error("Unable to assign to a random port");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@valkyr/testcontainers",
|
"name": "@valkyr/testcontainers",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./mod.ts",
|
".": "./mod.ts",
|
||||||
"./postgres": "./containers/postgres.ts"
|
"./postgres": "./containers/postgres.ts"
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"imports": {
|
"imports": {
|
||||||
"std/": "https://deno.land/std@0.224.0/",
|
"std/": "https://deno.land/std@0.224.0/",
|
||||||
"delay": "npm:delay@6.0.0",
|
"delay": "npm:delay@6.0.0",
|
||||||
"port": "npm:get-port@7.1.0",
|
"port": "https://deno.land/x/getport@v2.1.2/mod.ts",
|
||||||
"postgres": "npm:postgres@3.4.4"
|
"postgres": "npm:postgres@3.4.4"
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
|
|||||||
9
deno.lock
generated
9
deno.lock
generated
@@ -3,7 +3,6 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"specifiers": {
|
"specifiers": {
|
||||||
"npm:delay@6.0.0": "npm:delay@6.0.0",
|
"npm:delay@6.0.0": "npm:delay@6.0.0",
|
||||||
"npm:get-port@7.1.0": "npm:get-port@7.1.0",
|
|
||||||
"npm:postgres@3.4.4": "npm:postgres@3.4.4"
|
"npm:postgres@3.4.4": "npm:postgres@3.4.4"
|
||||||
},
|
},
|
||||||
"npm": {
|
"npm": {
|
||||||
@@ -11,10 +10,6 @@
|
|||||||
"integrity": "sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==",
|
"integrity": "sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==",
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
},
|
},
|
||||||
"get-port@7.1.0": {
|
|
||||||
"integrity": "sha512-QB9NKEeDg3xxVwCCwJQ9+xycaz6pBB6iQ76wiWMl1927n0Kir6alPiP+yuiICLLU4jpMe08dXfpebuQppFA2zw==",
|
|
||||||
"dependencies": {}
|
|
||||||
},
|
|
||||||
"postgres@3.4.4": {
|
"postgres@3.4.4": {
|
||||||
"integrity": "sha512-IbyN+9KslkqcXa8AO9fxpk97PA4pzewvpi2B3Dwy9u4zpV32QicaEdgmF3eSQUzdRk7ttDHQejNgAEr4XoeH4A==",
|
"integrity": "sha512-IbyN+9KslkqcXa8AO9fxpk97PA4pzewvpi2B3Dwy9u4zpV32QicaEdgmF3eSQUzdRk7ttDHQejNgAEr4XoeH4A==",
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
@@ -56,12 +51,12 @@
|
|||||||
"https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",
|
"https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2",
|
||||||
"https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e",
|
"https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e",
|
||||||
"https://deno.land/std@0.224.0/testing/_test_suite.ts": "f10a8a6338b60c403f07a76f3f46bdc9f1e1a820c0a1decddeb2949f7a8a0546",
|
"https://deno.land/std@0.224.0/testing/_test_suite.ts": "f10a8a6338b60c403f07a76f3f46bdc9f1e1a820c0a1decddeb2949f7a8a0546",
|
||||||
"https://deno.land/std@0.224.0/testing/bdd.ts": "3e4de4ff6d8f348b5574661cef9501b442046a59079e201b849d0e74120d476b"
|
"https://deno.land/std@0.224.0/testing/bdd.ts": "3e4de4ff6d8f348b5574661cef9501b442046a59079e201b849d0e74120d476b",
|
||||||
|
"https://deno.land/x/getport@v2.1.2/mod.ts": "e1d629c14008fc1da85278615c55e9356c206d35054577c49639248e3c036f17"
|
||||||
},
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"npm:delay@6.0.0",
|
"npm:delay@6.0.0",
|
||||||
"npm:get-port@7.1.0",
|
|
||||||
"npm:postgres@3.4.4"
|
"npm:postgres@3.4.4"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,6 @@ import { Container } from "./container.ts";
|
|||||||
import { Image } from "./image.ts";
|
import { Image } from "./image.ts";
|
||||||
import { modem } from "./modem.ts";
|
import { modem } from "./modem.ts";
|
||||||
|
|
||||||
/**
|
|
||||||
* @module
|
|
||||||
*
|
|
||||||
* A simple wrapper for pulling a docker image, and creating docker containers.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* import { docker } from "@valkyr/testcontainers";
|
|
||||||
*
|
|
||||||
* await docker.pullImage("docker:image");
|
|
||||||
*
|
|
||||||
* const container = await docker.createContainer({ Image: "docker:image" });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export class Docker {
|
export class Docker {
|
||||||
/**
|
/**
|
||||||
* Create a new docker container.
|
* Create a new docker container.
|
||||||
|
|||||||
Reference in New Issue
Block a user