diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 428f143fa..ae43194e9 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -11,12 +11,11 @@ name: Run tests jobs: test: runs-on: ubuntu-latest - container: 'node:18' steps: - - name: Install dependencies for cypress - run: | - apt-get update - apt-get install -y xvfb libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 + - name: Use Node.js 18.x + uses: actions/setup-node@v1 + with: + node-version: 18.x - uses: actions/checkout@v3 with: fetch-depth: 1 @@ -67,32 +66,61 @@ jobs: result-file: packages/datalib/result.json action-name: Datalib (perspectives) test results services: - postgres: + postgres-integr: image: postgres env: POSTGRES_PASSWORD: Pwd2020Db options: '--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5' - mysql: + ports: + - '15000:5432' + mysql-integr: image: 'mysql:8.0.18' env: MYSQL_ROOT_PASSWORD: Pwd2020Db - mssql: + ports: + - '15001:3306' + mssql-integr: image: mcr.microsoft.com/mssql/server env: ACCEPT_EULA: 'Y' SA_PASSWORD: Pwd2020Db MSSQL_PID: Express - clickhouse: + ports: + - '15002:1433' + clickhouse-integr: image: 'bitnami/clickhouse:24.8.4' env: CLICKHOUSE_ADMIN_PASSWORD: Pwd2020Db - oracle: + ports: + - '15005:8123' + oracle-integr: image: 'gvenzl/oracle-xe:21-slim' env: ORACLE_PASSWORD: Pwd2020Db + ports: + - '15006:1521' + postgres-cypress: + image: postgres + options: '--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5' + env: + POSTGRES_PASSWORD: Pwd2020Db + ports: + - '16000:5432' + mysql-cypress: + image: 'mysql:8.0.18' + ports: + - '16004:3306' + env: + MYSQL_ROOT_PASSWORD: Pwd2020Db mysql-ssh-login: image: 'ghcr.io/dbgate/mysql-ssh-login:latest' + ports: + - '16006:22' mysql-ssh-keyfile: image: 'ghcr.io/dbgate/mysql-ssh-keyfile:latest' + ports: + - '16008:22' dex: image: 'ghcr.io/dbgate/dex:latest' + ports: + - '16009:5556' diff --git a/e2e-tests/containers/dex/dex-config.yaml b/e2e-tests/containers/dex/dex-config.yaml index e69ab6e68..190200844 100644 --- a/e2e-tests/containers/dex/dex-config.yaml +++ b/e2e-tests/containers/dex/dex-config.yaml @@ -1,4 +1,4 @@ -issuer: http://dex:5556/dex +issuer: http://localhost:16009/dex storage: type: memory web: diff --git a/e2e-tests/cypress.config.js b/e2e-tests/cypress.config.js index b90aa0e96..e0dcc81d3 100644 --- a/e2e-tests/cypress.config.js +++ b/e2e-tests/cypress.config.js @@ -20,10 +20,10 @@ module.exports = defineConfig({ serverProcess = exec('yarn start:add-connection'); break; case 'portal': - serverProcess = exec('yarn start:portal:local'); + serverProcess = exec('yarn start:portal'); break; case 'oauth': - serverProcess = exec('yarn start:oauth:local'); + serverProcess = exec('yarn start:oauth'); break; } diff --git a/e2e-tests/cypress/e2e/add-connection.cy.js b/e2e-tests/cypress/e2e/add-connection.cy.js index a36782ab6..00cfa70b7 100644 --- a/e2e-tests/cypress/e2e/add-connection.cy.js +++ b/e2e-tests/cypress/e2e/add-connection.cy.js @@ -7,18 +7,12 @@ describe('Add connection', () => { }); it('adds connection', () => { - const runOnCI = Cypress.env('runOnCI'); - cy.visit('http://localhost:3000'); // cy.get('[data-testid=ConnectionList_buttonNewConnection]').click(); cy.get('[data-testid=ConnectionDriverFields_connectionType]').select('MySQL'); cy.get('[data-testid=ConnectionDriverFields_user]').clear().type('root'); cy.get('[data-testid=ConnectionDriverFields_password]').clear().type('Pwd2020Db'); - if (runOnCI) { - cy.get('[data-testid=ConnectionDriverFields_server]').clear().type('mysql'); - } else { - cy.get('[data-testid=ConnectionDriverFields_port]').clear().type('16004'); - } + cy.get('[data-testid=ConnectionDriverFields_port]').clear().type('16004'); cy.get('[data-testid=ConnectionDriverFields_displayName]').clear().type('test-mysql-1'); // test connection @@ -32,8 +26,6 @@ describe('Add connection', () => { }); it('SSH connection - user + password', () => { - const runOnCI = Cypress.env('runOnCI'); - cy.visit('http://localhost:3000'); cy.contains('Connections'); @@ -52,19 +44,13 @@ describe('Add connection', () => { cy.get('[data-testid=ConnectionSshTunnelFields_useSshTunnel]').check(); cy.get('[data-testid=ConnectionSshTunnelFields_sshLogin]').clear().type('root'); cy.get('[data-testid=ConnectionSshTunnelFields_sshPassword]').clear().type('root'); - if (runOnCI) { - cy.get('[data-testid=ConnectionSshTunnelFields_sshHost]').clear().type('mysql-ssh-login'); - } else { - cy.get('[data-testid=ConnectionSshTunnelFields_sshPort]').clear().type('16006'); - } + cy.get('[data-testid=ConnectionSshTunnelFields_sshPort]').clear().type('16006'); cy.get('[data-testid=ConnectionTab_buttonSave]').click(); cy.get('[data-testid=ConnectionTab_buttonConnect]').click(); cy.contains('performance_schema'); }); it('SSH connection - keyfile', () => { - const runOnCI = Cypress.env('runOnCI'); - cy.visit('http://localhost:3000'); cy.contains('Connections'); @@ -87,30 +73,20 @@ describe('Add connection', () => { cy.get('[data-testid=ConnectionSshTunnelFields_sshKeyfile]') .clear() .type(path.join(Cypress.config('fileServerFolder'), 'cypress', 'e2e', 'mykey')); - if (runOnCI) { - cy.get('[data-testid=ConnectionSshTunnelFields_sshHost]').clear().type('mysql-ssh-keyfile'); - } else { - cy.get('[data-testid=ConnectionSshTunnelFields_sshPort]').clear().type('16008'); - } + cy.get('[data-testid=ConnectionSshTunnelFields_sshPort]').clear().type('16008'); cy.get('[data-testid=ConnectionTab_buttonSave]').click(); cy.get('[data-testid=ConnectionTab_buttonConnect]').click(); cy.contains('performance_schema'); }); it('ask password - mysql', () => { - const runOnCI = Cypress.env('runOnCI'); - cy.visit('http://localhost:3000'); - + cy.get('[data-testid=ConnectionList_buttonNewConnection]').click(); cy.get('[data-testid=ConnectionDriverFields_connectionType]').select('MySQL'); cy.get('[data-testid=ConnectionDriverFields_user]').clear().type('root'); cy.get('[data-testid=ConnectionDriverFields_password]').clear().type('Pwd2020Db'); - if (runOnCI) { - cy.get('[data-testid=ConnectionDriverFields_server]').clear().type('mysql'); - } else { - cy.get('[data-testid=ConnectionDriverFields_port]').clear().type('16004'); - } + cy.get('[data-testid=ConnectionDriverFields_port]').clear().type('16004'); cy.get('[data-testid=ConnectionDriverFields_displayName]').clear().type('test-mysql-2'); cy.testid('ConnectionDriverFields_passwordMode').select('askPassword'); diff --git a/e2e-tests/cypress/e2e/oauth.cy.js b/e2e-tests/cypress/e2e/oauth.cy.js index 34a7d5e6b..b763306a5 100644 --- a/e2e-tests/cypress/e2e/oauth.cy.js +++ b/e2e-tests/cypress/e2e/oauth.cy.js @@ -2,20 +2,10 @@ describe('OAuth', () => { it('OAuth login', () => { cy.visit('http://localhost:3000'); - const runOnCI = Cypress.env('runOnCI'); - // login on DEX - if (runOnCI) { - cy.origin('http://dex:5556', () => { - cy.get('#login').clear().type('test@example.com'); - cy.get('#password').clear().type('test'); - cy.get('#submit-login').click(); - }); - } else { - cy.get('#login').clear().type('test@example.com'); - cy.get('#password').clear().type('test'); - cy.get('#submit-login').click(); - } + cy.get('#login').clear().type('test@example.com'); + cy.get('#password').clear().type('test'); + cy.get('#submit-login').click(); // check DbGate connection cy.contains('MySql-connection').click(); diff --git a/e2e-tests/dex-config.yaml b/e2e-tests/dex-config.yaml deleted file mode 100644 index 190200844..000000000 --- a/e2e-tests/dex-config.yaml +++ /dev/null @@ -1,22 +0,0 @@ -issuer: http://localhost:16009/dex -storage: - type: memory -web: - http: 0.0.0.0:5556 - -oauth2: - skipApprovalScreen: true - -staticClients: - - id: my-app - redirectURIs: - - 'http://localhost:3000/' - name: 'My Test App' - secret: my-secret - -enablePasswordDB: true -staticPasswords: - - email: "test@example.com" - hash: "$2y$10$JcmlXnV1y7.egUdKwYNbseOnqYVIGc323gtvvHh4ZuSPZB30veYZy" - username: "test" - userID: "1234" diff --git a/e2e-tests/docker-compose.yaml b/e2e-tests/docker-compose.yaml index 3a27aec06..0fbb5b93a 100644 --- a/e2e-tests/docker-compose.yaml +++ b/e2e-tests/docker-compose.yaml @@ -22,19 +22,16 @@ services: restart: always ports: - 16005:3306 - - 16006:22 + - "16006:22" mysql-ssh-keyfile: build: containers/mysql-ssh-keyfile restart: always ports: - 16007:3306 - - 16008:22 + - "16008:22" dex: - image: dexidp/dex:v2.35.3 + build: containers/dex ports: - "16009:5556" - volumes: - - ./dex-config.yaml:/etc/dex/cfg/config.yaml - command: ["dex", "serve", "/etc/dex/cfg/config.yaml"] diff --git a/e2e-tests/env/oauth-ci/.env b/e2e-tests/env/oauth-ci/.env deleted file mode 100644 index 47627dff5..000000000 --- a/e2e-tests/env/oauth-ci/.env +++ /dev/null @@ -1,15 +0,0 @@ -CONNECTIONS=mysql - -LABEL_mysql=MySql-connection -SERVER_mysql=mysql -USER_mysql=root -PASSWORD_mysql=Pwd2020Db -PORT_mysql=3306 -ENGINE_mysql=mysql@dbgate-plugin-mysql - -OAUTH_AUTH=http://dex:5556/dex/auth -OAUTH_TOKEN=http://dex:5556/dex/token -OAUTH_CLIENT_ID=my-app -OAUTH_CLIENT_SECRET=my-secret -OAUTH_LOGIN_FIELD=username -OAUTH_SCOPE=openid \ No newline at end of file diff --git a/e2e-tests/env/oauth-local/.env b/e2e-tests/env/oauth/.env similarity index 100% rename from e2e-tests/env/oauth-local/.env rename to e2e-tests/env/oauth/.env diff --git a/e2e-tests/env/portal-ci/.env b/e2e-tests/env/portal-ci/.env deleted file mode 100644 index eedfe0fe5..000000000 --- a/e2e-tests/env/portal-ci/.env +++ /dev/null @@ -1,22 +0,0 @@ -CONNECTIONS=mysql,postgres,pgask - -LABEL_mysql=MySql-connection -SERVER_mysql=mysql -USER_mysql=root -PASSWORD_mysql=Pwd2020Db -PORT_mysql=3306 -ENGINE_mysql=mysql@dbgate-plugin-mysql - -LABEL_postgres=Postgres-connection -SERVER_postgres=postgres -USER_postgres=postgres -PASSWORD_postgres=Pwd2020Db -PORT_postgres=5432 -ENGINE_postgres=postgres@dbgate-plugin-postgres - -LABEL_pgask=Postgres-ask-connection -SERVER_pgask=postgres -USER_pgask=postgres -PORT_pgask=5432 -ENGINE_pgask=postgres@dbgate-plugin-postgres -PASSWORD_MODE_pgask=askUser diff --git a/e2e-tests/env/portal-local/.env b/e2e-tests/env/portal/.env similarity index 100% rename from e2e-tests/env/portal-local/.env rename to e2e-tests/env/portal/.env diff --git a/e2e-tests/package.json b/e2e-tests/package.json index fb88f3e76..260a742a9 100644 --- a/e2e-tests/package.json +++ b/e2e-tests/package.json @@ -15,24 +15,15 @@ "scripts": { "cy:open": "cypress open --config experimentalInteractiveRunEvents=true", - "cy:run:add-connection:local": "cypress run --spec cypress/e2e/add-connection.cy.js", - "cy:run:add-connection:ci": "cypress run --env runOnCI=true --spec cypress/e2e/add-connection.cy.js", - - "cy:run:portal:local": "cypress run --spec cypress/e2e/portal.cy.js", - "cy:run:portal:ci": "cypress run --env runOnCI=true --spec cypress/e2e/portal.cy.js", - - "cy:run:oauth:local": "cypress run --spec cypress/e2e/oauth.cy.js", - "cy:run:oauth:ci": "cypress run --env runOnCI=true --spec cypress/e2e/oauth.cy.js", + "cy:run:add-connection": "cypress run --spec cypress/e2e/add-connection.cy.js", + "cy:run:portal": "cypress run --spec cypress/e2e/portal.cy.js", + "cy:run:oauth": "cypress run --spec cypress/e2e/oauth.cy.js", "start:add-connection": "cd .. && node packer/build/bundle.js --listen-api --run-e2e-tests", + "start:portal": "cd .. && env-cmd -f e2e-tests/env/portal/.env node e2e-tests/init/portal.js && env-cmd -f e2e-tests/env/portal/.env node packer/build/bundle.js --listen-api --run-e2e-tests", + "start:oauth": "cd .. && env-cmd -f e2e-tests/env/oauth/.env node packer/build/bundle.js --listen-api --run-e2e-tests", - "start:portal:local": "cd .. && env-cmd -f e2e-tests/env/portal-local/.env node e2e-tests/init/portal.js && env-cmd -f e2e-tests/env/portal-local/.env node packer/build/bundle.js --listen-api --run-e2e-tests", - "start:portal:ci": "cd .. && env-cmd -f e2e-tests/env/portal-ci/.env node e2e-tests/init/portal.js && env-cmd -f e2e-tests/env/portal-ci/.env node packer/build/bundle.js --listen-api --run-e2e-tests", - - "start:oauth:local": "cd .. && env-cmd -f e2e-tests/env/oauth-local/.env node packer/build/bundle.js --listen-api --run-e2e-tests", - "start:oauth:ci": "cd .. && env-cmd -f e2e-tests/env/oauth-ci/.env node packer/build/bundle.js --listen-api --run-e2e-tests", - - "test:ci": "start-server-and-test start:add-connection http://localhost:3000 cy:run:add-connection:ci && start-server-and-test start:portal:ci http://localhost:3000 cy:run:portal:ci && start-server-and-test start:oauth:ci http://localhost:3000 cy:run:oauth:ci", - "test:local": "start-server-and-test start:add-connection http://localhost:3000 cy:run:add-connection:local && start-server-and-test start:portal:local http://localhost:3000 cy:run:portal:local && start-server-and-test start:oauth:local http://localhost:3000 cy:run:oauth:local" + "test": "start-server-and-test start:add-connection http://localhost:3000 cy:run:add-connection && start-server-and-test start:portal http://localhost:3000 cy:run:portal && start-server-and-test start:oauth http://localhost:3000 cy:run:oauth", + "test:ci": "yarn test" } } diff --git a/integration-tests/__tests__/schema-tests.spec.js b/integration-tests/__tests__/schema-tests.spec.js index d31fcb13b..fda045c90 100644 --- a/integration-tests/__tests__/schema-tests.spec.js +++ b/integration-tests/__tests__/schema-tests.spec.js @@ -1,7 +1,7 @@ const stableStringify = require('json-stable-stringify'); const _ = require('lodash'); const fp = require('lodash/fp'); -const { testWrapper, extractConnection } = require('../tools'); +const { testWrapper } = require('../tools'); const engines = require('../engines'); const { runCommandOnDriver } = require('dbgate-tools'); @@ -62,7 +62,7 @@ describe('Schema tests', () => { await runCommandOnDriver(handle, driver, dmp => dmp.createSchema('myschema')); const schemaConnDef = { - ...extractConnection(engine), + ...engine.connection, database: `${handle.database}::myschema`, }; diff --git a/integration-tests/engines.js b/integration-tests/engines.js index 13985867f..d2617d2f6 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -19,10 +19,6 @@ const mysqlEngine = { engine: 'mysql@dbgate-plugin-mysql', password: 'Pwd2020Db', user: 'root', - server: 'mysql', - port: 3306, - }, - local: { server: 'localhost', port: 15001, }, @@ -170,10 +166,6 @@ const mariaDbEngine = { engine: 'mariadb@dbgate-plugin-mysql', password: 'Pwd2020Db', user: 'root', - server: 'mysql', - port: 3306, - }, - local: { server: 'localhost', port: 15004, }, @@ -194,10 +186,6 @@ const postgreSqlEngine = { engine: 'postgres@dbgate-plugin-postgres', password: 'Pwd2020Db', user: 'postgres', - server: 'postgres', - port: 5432, - }, - local: { server: 'localhost', port: 15000, }, @@ -370,10 +358,6 @@ const sqlServerEngine = { engine: 'mssql@dbgate-plugin-mssql', password: 'Pwd2020Db', user: 'sa', - server: 'mssql', - port: 1433, - }, - local: { server: 'localhost', port: 15002, }, @@ -521,10 +505,6 @@ const cockroachDbEngine = { connection: { engine: 'cockroach@dbgate-plugin-postgres', user: 'root', - server: 'cockroachdb', - port: 26257, - }, - local: { server: 'localhost', port: 15003, }, @@ -535,11 +515,8 @@ const clickhouseEngine = { label: 'ClickHouse', connection: { engine: 'clickhouse@dbgate-plugin-clickhouse', - databaseUrl: 'http://clickhouse:8123', - password: 'Pwd2020Db', - }, - local: { databaseUrl: 'http://localhost:15005', + password: 'Pwd2020Db', }, objects: [views], skipDataModifications: true, @@ -562,13 +539,9 @@ const oracleEngine = { engine: 'oracle@dbgate-plugin-oracle', password: 'Pwd2020Db', user: 'system', - server: 'oracle', - port: 1521, - serviceName: 'xe', - }, - local: { server: 'localhost', port: 15006, + serviceName: 'xe', }, skipOnCI: false, dbSnapshotBySeconds: true, diff --git a/integration-tests/tools.js b/integration-tests/tools.js index 96b68024d..5f39398c2 100644 --- a/integration-tests/tools.js +++ b/integration-tests/tools.js @@ -9,21 +9,8 @@ function randomDbName(dialect) { return res; } -function extractConnection(engine) { - const { connection } = engine; - - if (process.env.LOCALTEST && engine.local) { - return { - ...connection, - ...engine.local, - }; - } - - return connection; -} - async function connect(engine, database) { - const connection = extractConnection(engine); + const { connection } = engine; const driver = requireEngineDriver(connection); if (engine.generateDbFile) { @@ -48,7 +35,7 @@ async function connect(engine, database) { } async function prepareConnection(engine, database) { - const connection = extractConnection(engine); + const { connection } = engine; const driver = requireEngineDriver(connection); if (engine.generateDbFile) { @@ -97,7 +84,6 @@ const testWrapperPrepareOnly = module.exports = { randomDbName, connect, - extractConnection, testWrapper, testWrapperPrepareOnly, }; diff --git a/integration-tests/wait.js b/integration-tests/wait.js index a61339bb3..fccba3929 100644 --- a/integration-tests/wait.js +++ b/integration-tests/wait.js @@ -1,13 +1,12 @@ const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver'); const engines = require('./engines'); -const { extractConnection } = require('./tools'); global.DBGATE_PACKAGES = { 'dbgate-tools': require('dbgate-tools'), 'dbgate-sqltree': require('dbgate-sqltree'), }; async function connectEngine(engine) { - const connection = extractConnection(engine); + const { connection } = engine; const driver = requireEngineDriver(connection); for (;;) { try { diff --git a/workflow-templates/run-tests.yaml b/workflow-templates/run-tests.yaml index a15f6b9be..7c6fafef4 100644 --- a/workflow-templates/run-tests.yaml +++ b/workflow-templates/run-tests.yaml @@ -10,13 +10,12 @@ on: jobs: test: runs-on: ubuntu-latest - container: node:18 steps: - - name: Install dependencies for cypress - run: | - apt-get update - apt-get install -y xvfb libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 + - name: Use Node.js 18.x + uses: actions/setup-node@v1 + with: + node-version: 18.x - uses: actions/checkout@v3 with: @@ -79,7 +78,7 @@ jobs: action-name: Datalib (perspectives) test results services: - postgres: + postgres-integr: image: postgres env: POSTGRES_PASSWORD: Pwd2020Db @@ -88,34 +87,70 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 15000:5432 - mysql: + mysql-integr: image: mysql:8.0.18 env: MYSQL_ROOT_PASSWORD: Pwd2020Db + ports: + - 15001:3306 - mssql: + mssql-integr: image: mcr.microsoft.com/mssql/server env: ACCEPT_EULA: Y SA_PASSWORD: Pwd2020Db MSSQL_PID: Express + ports: + - 15002:1433 - clickhouse: + clickhouse-integr: image: bitnami/clickhouse:24.8.4 env: CLICKHOUSE_ADMIN_PASSWORD: Pwd2020Db + ports: + - 15005:8123 - oracle: + oracle-integr: image: gvenzl/oracle-xe:21-slim env: ORACLE_PASSWORD: Pwd2020Db - + ports: + - 15006:1521 + + + postgres-cypress: + image: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: Pwd2020Db + ports: + - 16000:5432 + + mysql-cypress: + image: mysql:8.0.18 + ports: + - 16004:3306 + env: + MYSQL_ROOT_PASSWORD: Pwd2020Db + mysql-ssh-login: image: ghcr.io/dbgate/mysql-ssh-login:latest + ports: + - '16006:22' mysql-ssh-keyfile: image: ghcr.io/dbgate/mysql-ssh-keyfile:latest + ports: + - '16008:22' dex: image: ghcr.io/dbgate/dex:latest + ports: + - 16009:5556