|
| 1 | +import { TrinoDriver } from '../src/TrinoDriver'; |
| 2 | + |
| 3 | +const path = require('path'); |
| 4 | +const { DockerComposeEnvironment, Wait } = require('testcontainers'); |
| 5 | + |
| 6 | +describe('TrinoDriver', () => { |
| 7 | + jest.setTimeout(6 * 60 * 1000); |
| 8 | + |
| 9 | + let env: any; |
| 10 | + let config: any; |
| 11 | + |
| 12 | + const doWithDriver = async (callback: any) => { |
| 13 | + const driver = new TrinoDriver(config); |
| 14 | + |
| 15 | + await callback(driver); |
| 16 | + }; |
| 17 | + |
| 18 | + // eslint-disable-next-line consistent-return,func-names |
| 19 | + beforeAll(async () => { |
| 20 | + const authOpts = { |
| 21 | + basic_auth: { |
| 22 | + user: 'presto', |
| 23 | + password: '' |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + if (process.env.TEST_PRESTO_HOST) { |
| 28 | + config = { |
| 29 | + host: process.env.TEST_PRESTO_HOST || 'localhost', |
| 30 | + port: process.env.TEST_PRESTO_PORT || '8080', |
| 31 | + catalog: process.env.TEST_PRESTO_CATALOG || 'tpch', |
| 32 | + schema: 'sf1', |
| 33 | + ...authOpts |
| 34 | + }; |
| 35 | + |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + const dc = new DockerComposeEnvironment( |
| 40 | + path.resolve(path.dirname(__filename), '../../'), |
| 41 | + 'docker-compose.yml' |
| 42 | + ); |
| 43 | + |
| 44 | + env = await dc |
| 45 | + .withStartupTimeout(240 * 1000) |
| 46 | + .withWaitStrategy('coordinator', Wait.forHealthCheck()) |
| 47 | + .up(); |
| 48 | + |
| 49 | + config = { |
| 50 | + host: env.getContainer('coordinator').getHost(), |
| 51 | + port: env.getContainer('coordinator').getMappedPort(8080), |
| 52 | + catalog: 'tpch', |
| 53 | + schema: 'sf1', |
| 54 | + ...authOpts |
| 55 | + }; |
| 56 | + }); |
| 57 | + |
| 58 | + // eslint-disable-next-line consistent-return,func-names |
| 59 | + afterAll(async () => { |
| 60 | + if (env) { |
| 61 | + await env.down(); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + it('should construct', async () => { |
| 66 | + await doWithDriver(() => { |
| 67 | + // |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + // eslint-disable-next-line func-names |
| 72 | + it('should test connection', async () => { |
| 73 | + await doWithDriver(async (driver: any) => { |
| 74 | + await driver.testConnection(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + // eslint-disable-next-line func-names |
| 79 | + it('should test informationSchemaQuery', async () => { |
| 80 | + await doWithDriver(async (driver: any) => { |
| 81 | + const informationSchemaQuery = driver.informationSchemaQuery(); |
| 82 | + expect(informationSchemaQuery).toContain('columns.table_schema = \'sf1\''); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments