diff --git a/.env.dev.sample b/.env.dev.sample new file mode 100644 index 00000000..4e4554c4 --- /dev/null +++ b/.env.dev.sample @@ -0,0 +1,4 @@ +YDB_ANONYMOUS_CREDENTIALS=1 +YDB_SSL_ROOT_CERTIFICATES_FILE=../slo-tests/playground/data/ydb_certs/ca.pem +YDB_ENDPOINT=grpc://:<2135 / 2136> +YDB_LOG_LEVEL=debug diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd5c8dc3..b7a75252 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: services: ydb: - image: ghcr.io/ydb-platform/local-ydb:nightly + image: ydbplatform/local-ydb:24.1 ports: - 2135:2135 - 2136:2136 diff --git a/.gitignore b/.gitignore index 9860352e..0d346edf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ + +.env + #npm npm-debug.log* node_modules diff --git a/package-lock.json b/package-lock.json index 617f3887..a64d65e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "@types/uuid": "^8.3.4", "@yandex-cloud/nodejs-sdk": "^2.0.0", "cross-env": "^7.0.3", + "dotenv": "^16.4.5", "husky": "^7.0.4", "npm-run-all": "^4.1.5", "rimraf": "^5.0.1", @@ -3839,6 +3840,19 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dotgitignore": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/dotgitignore/-/dotgitignore-2.1.0.tgz", @@ -13168,6 +13182,12 @@ "is-obj": "^2.0.0" } }, + "dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true + }, "dotgitignore": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/dotgitignore/-/dotgitignore-2.1.0.tgz", diff --git a/package.json b/package.json index 3402626b..5dbf353b 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@types/uuid": "^8.3.4", "@yandex-cloud/nodejs-sdk": "^2.0.0", "cross-env": "^7.0.3", + "dotenv": "^16.4.5", "husky": "^7.0.4", "npm-run-all": "^4.1.5", "rimraf": "^5.0.1", diff --git a/src/__tests__/e2e/connection.test.ts b/src/__tests__/e2e/connection.test.ts index 21477b40..92f912b1 100644 --- a/src/__tests__/e2e/connection.test.ts +++ b/src/__tests__/e2e/connection.test.ts @@ -1,8 +1,10 @@ import {initDriver, destroyDriver} from "../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + describe('Connection', () => { it('Test GRPC connection', async () => { - let driver = await initDriver({endpoint: 'grpc://localhost:2136'}); + let driver = await initDriver({endpoint: process.env.YDB_ENDPOINT || 'grpc://localhost:2136'}); await driver.tableClient.withSession(async (session) => { await session.executeQuery('SELECT 1'); }); @@ -10,7 +12,7 @@ describe('Connection', () => { }); it('Test GRPCS connection', async () => { - let driver = await initDriver({endpoint: 'grpcs://localhost:2135'}); + let driver = await initDriver({endpoint: process.env.YDB_ENDPOINT || 'grpcs://localhost:2135'}); await driver.tableClient.withSession(async (session) => { await session.executeQuery('SELECT 1'); }); diff --git a/src/__tests__/e2e/query-service/method-execute.ts b/src/__tests__/e2e/query-service/method-execute.ts index cfab573f..fa842aaf 100644 --- a/src/__tests__/e2e/query-service/method-execute.ts +++ b/src/__tests__/e2e/query-service/method-execute.ts @@ -11,8 +11,10 @@ import {ctxSymbol} from "../../../query/symbols"; import StatsMode = Ydb.Query.StatsMode; import ExecMode = Ydb.Query.ExecMode; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const DATABASE = '/local'; -const ENDPOINT = 'grpc://localhost:2136'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2136'; const TABLE_NAME = 'test_table_1' describe('Query.execute()', () => { diff --git a/src/__tests__/e2e/query-service/query-service-client.ts b/src/__tests__/e2e/query-service/query-service-client.ts index ad79237b..9d2936d1 100644 --- a/src/__tests__/e2e/query-service/query-service-client.ts +++ b/src/__tests__/e2e/query-service/query-service-client.ts @@ -6,8 +6,10 @@ import fs from "fs"; import {AUTO_TX} from "../../../table"; import {QuerySession, IExecuteResult} from "../../../query"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const DATABASE = '/local'; -const ENDPOINT = 'grpcs://localhost:2135'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2135'; describe('Query client', () => { diff --git a/src/__tests__/e2e/query-service/rows-conversion.ts b/src/__tests__/e2e/query-service/rows-conversion.ts index c828e726..4d887fe3 100644 --- a/src/__tests__/e2e/query-service/rows-conversion.ts +++ b/src/__tests__/e2e/query-service/rows-conversion.ts @@ -9,8 +9,10 @@ import {getDefaultLogger} from "../../../logger/get-default-logger"; import {ctxSymbol} from "../../../query/symbols"; import {Context} from "../../../context"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const DATABASE = '/local'; -const ENDPOINT = 'grpcs://localhost:2136'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2136'; const TABLE_NAME = 'test_table_3' interface IRow { diff --git a/src/__tests__/e2e/query-service/transactions.ts b/src/__tests__/e2e/query-service/transactions.ts index 897fe5e8..88e336ba 100644 --- a/src/__tests__/e2e/query-service/transactions.ts +++ b/src/__tests__/e2e/query-service/transactions.ts @@ -8,8 +8,10 @@ import {getDefaultLogger} from "../../../logger/get-default-logger"; import {ctxSymbol} from "../../../query/symbols"; import {Context} from "../../../context"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const DATABASE = '/local'; -const ENDPOINT = 'grpc://localhost:2136'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2136'; describe('Query service transactions', () => { diff --git a/src/__tests__/e2e/retries.test.ts b/src/__tests__/e2e/retries.test.ts index 20170b45..410a9e26 100644 --- a/src/__tests__/e2e/retries.test.ts +++ b/src/__tests__/e2e/retries.test.ts @@ -24,6 +24,8 @@ import {pessimizable} from "../../utils"; import {destroyDriver, initDriver} from "../../utils/test"; import {LogLevel, SimpleLogger} from "../../logger/simple-logger"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const logger = new SimpleLogger({level: LogLevel.error}); class ErrorThrower { constructor(public endpoint: Endpoint) {} diff --git a/src/__tests__/e2e/table-service/alter-table.test.ts b/src/__tests__/e2e/table-service/alter-table.test.ts index a49db325..19b3daea 100644 --- a/src/__tests__/e2e/table-service/alter-table.test.ts +++ b/src/__tests__/e2e/table-service/alter-table.test.ts @@ -10,6 +10,8 @@ import { } from "../../../table"; import {initDriver, destroyDriver} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const getTableName = () => `table_alter_${Math.trunc(1000 * Math.random())}`; describe('Alter table', () => { diff --git a/src/__tests__/e2e/table-service/bulk-upsert.test.ts b/src/__tests__/e2e/table-service/bulk-upsert.test.ts index 125a70f0..560db7e0 100644 --- a/src/__tests__/e2e/table-service/bulk-upsert.test.ts +++ b/src/__tests__/e2e/table-service/bulk-upsert.test.ts @@ -3,6 +3,8 @@ import Driver from '../../../driver'; import {TableSession} from "../../../table"; import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + async function readTable(session: TableSession): Promise { const rows: Row[] = []; diff --git a/src/__tests__/e2e/table-service/bytestring-identity.test.ts b/src/__tests__/e2e/table-service/bytestring-identity.test.ts index a1f97370..ef8d8f4b 100644 --- a/src/__tests__/e2e/table-service/bytestring-identity.test.ts +++ b/src/__tests__/e2e/table-service/bytestring-identity.test.ts @@ -4,6 +4,8 @@ import {withRetries} from '../../../retries_obsoleted'; import {Column, TableSession, TableDescription} from "../../../table"; import {initDriver, destroyDriver, TABLE} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + async function createTable(session: TableSession) { await session.dropTable(TABLE); await session.createTable( diff --git a/src/__tests__/e2e/table-service/create-table.test.ts b/src/__tests__/e2e/table-service/create-table.test.ts index 834cff36..3546aa2f 100644 --- a/src/__tests__/e2e/table-service/create-table.test.ts +++ b/src/__tests__/e2e/table-service/create-table.test.ts @@ -5,6 +5,8 @@ import {Ydb} from 'ydb-sdk-proto'; import {Column, DescribeTableSettings, TableDescription} from "../../../table"; import {initDriver, destroyDriver} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const getTableName = () => `table_create_${Math.trunc(100000 * Math.random())}`; describe('Create table', () => { diff --git a/src/__tests__/e2e/table-service/graceful-session-close.test.ts b/src/__tests__/e2e/table-service/graceful-session-close.test.ts index a8853d47..36200666 100644 --- a/src/__tests__/e2e/table-service/graceful-session-close.test.ts +++ b/src/__tests__/e2e/table-service/graceful-session-close.test.ts @@ -6,6 +6,8 @@ import {initDriver, destroyDriver} from "../../../utils/test"; const SHUTDOWN_URL = process.env.YDB_SHUTDOWN_URL || 'http://localhost:8765/actors/kqp_proxy?force_shutdown=all'; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + describe('Graceful session close', () => { // TODO: Fix and enable test nce issue will be resolved https://github.com/ydb-platform/ydb/issues/2981 diff --git a/src/__tests__/e2e/table-service/read-table.test.ts b/src/__tests__/e2e/table-service/read-table.test.ts index c6a8ee6a..35bda833 100644 --- a/src/__tests__/e2e/table-service/read-table.test.ts +++ b/src/__tests__/e2e/table-service/read-table.test.ts @@ -3,6 +3,8 @@ import {TypedValues, TypedData} from '../../../types'; import {ReadTableSettings, TableSession} from "../../../table"; import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + async function readTable(session: TableSession, settings: ReadTableSettings): Promise { const rows: TypedData[] = []; diff --git a/src/__tests__/e2e/table-service/scan-query.test.ts b/src/__tests__/e2e/table-service/scan-query.test.ts index 2e7de85e..775fbb5c 100644 --- a/src/__tests__/e2e/table-service/scan-query.test.ts +++ b/src/__tests__/e2e/table-service/scan-query.test.ts @@ -3,6 +3,8 @@ import {TypedData} from '../../../types'; import {TableSession} from "../../../table"; import {Row, initDriver, destroyDriver, createTable, fillTableWithData, TABLE} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + async function executeScanQuery(session: TableSession): Promise { const query = `SELECT * FROM ${TABLE};`; diff --git a/src/__tests__/e2e/table-service/types.test.ts b/src/__tests__/e2e/table-service/types.test.ts index 0413904f..a1628db9 100644 --- a/src/__tests__/e2e/table-service/types.test.ts +++ b/src/__tests__/e2e/table-service/types.test.ts @@ -5,6 +5,8 @@ import {TypedData, TypedValues, Types} from '../../../types'; import NullValue = google.protobuf.NullValue; import {initDriver, destroyDriver} from "../../../utils/test"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + describe('Types', () => { let driver: Driver; diff --git a/src/__tests__/e2e/topic-service/internal.test.ts b/src/__tests__/e2e/topic-service/internal.test.ts index af38d1a5..d0d6e36f 100644 --- a/src/__tests__/e2e/topic-service/internal.test.ts +++ b/src/__tests__/e2e/topic-service/internal.test.ts @@ -6,8 +6,10 @@ import {TopicService} from "../../../topic"; import {google, Ydb} from "ydb-sdk-proto"; import {openReadStreamWithEvents, openWriteStreamWithEvents} from "../../../topic/symbols"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); + const DATABASE = '/local'; -const ENDPOINT = 'grpc://localhost:2136'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2136'; describe('Topic: General', () => { let discoveryService: DiscoveryService; diff --git a/src/__tests__/e2e/topic-service/send-messages.test.ts b/src/__tests__/e2e/topic-service/send-messages.test.ts index f54cfff5..fbb1cb34 100644 --- a/src/__tests__/e2e/topic-service/send-messages.test.ts +++ b/src/__tests__/e2e/topic-service/send-messages.test.ts @@ -1,10 +1,11 @@ import {AnonymousAuthService, Driver as YDB} from '../../../index'; import {google, Ydb} from "ydb-sdk-proto"; +if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); // create topic -describe('Topic: Send messages', () => { +xdescribe('Topic: Send messages', () => { let ydb: YDB | undefined; beforeEach(async () => { diff --git a/src/discovery/endpoint.ts b/src/discovery/endpoint.ts index 72ffa52b..7f18e41d 100644 --- a/src/discovery/endpoint.ts +++ b/src/discovery/endpoint.ts @@ -53,6 +53,12 @@ export class Endpoint extends Ydb.Discovery.EndpointInfo { } public toString(): string { + // TODO: Find out how to specify a host ip/name for local development + if (process.env.YDB_ENDPOINT) { + const str = process.env.YDB_ENDPOINT; + const n = str.indexOf('://'); // remove grpc(s)?:// + return n > 0 ? str.substr(n + 3) : str; + } // for development only let result = this.address; if (this.port) { result += ':' + this.port; diff --git a/src/utils/test/init-driver.ts b/src/utils/test/init-driver.ts index d463e954..a0abf5f0 100644 --- a/src/utils/test/init-driver.ts +++ b/src/utils/test/init-driver.ts @@ -13,7 +13,7 @@ export async function initDriver(settings?: Partial): Promise