Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as knex from 'knex';
- import * as Docker from 'dockerode';
- import { sleep } from '../util/time';
- import { waitForDatabase } from '../test/waitForDatabase';
- const docker = new Docker({ socketPath: '/var/run/docker.sock' });
- let dbContainer: Docker.Container;
- let knexClient: knex;
- beforeAll(async () => {
- dbContainer = await docker.createContainer({
- Image: 'pldin601/postgres:latest',
- Env: ['POSTGRES_USER=coins', 'POSTGRES_PASSWORD=coins', 'POSTGRES_DB=coins'],
- ExposedPorts: {
- '5432/tcp': {},
- },
- HostConfig: {
- PortBindings: { '5432/tcp': [{ HostPort: '' }] },
- },
- });
- await dbContainer.start();
- const { NetworkSettings: { Ports } } = await dbContainer.inspect();
- const port = Ports['5432/tcp'][0].HostPort;
- knexClient = knex({
- client: 'postgresql',
- connection: {
- host: '127.0.0.1',
- user: 'coins',
- password: 'coins',
- database: 'coins',
- port,
- },
- });
- await waitForDatabase(knexClient);
- }, 15000);
- test('Return correct time from database', async () => {
- const result = await knexClient.select(knexClient.raw('NOW() as time')).first();
- console.log(result['time']);
- });
- afterAll(async () => {
- await dbContainer.kill();
- await dbContainer.remove();
- });
Add Comment
Please, Sign In to add comment