diff --git a/qa-core/src/integrations/validators/mysql.spec.ts b/qa-core/src/integrations/validators/mysql.spec.ts new file mode 100644 index 0000000000..166085fdd5 --- /dev/null +++ b/qa-core/src/integrations/validators/mysql.spec.ts @@ -0,0 +1,68 @@ +import { GenericContainer } from "testcontainers" +import mysql from "../../../../packages/server/src/integrations/mysql" + +jest.unmock("mysql2/promise") + +describe("datasource validators", () => { + describe("mysql", () => { + let host: string + let port: number + + beforeAll(async () => { + const container = await new GenericContainer("mysql") + .withExposedPorts(3306) + .withEnv("MYSQL_ROOT_PASSWORD", "admin") + .withEnv("MYSQL_DATABASE", "db") + .withEnv("MYSQL_USER", "user") + .withEnv("MYSQL_PASSWORD", "password") + .start() + + host = container.getContainerIpAddress() + port = container.getMappedPort(3306) + }) + + it("test valid connection string", async () => { + const integration = new mysql.integration({ + host, + port, + user: "user", + database: "db", + password: "password", + rejectUnauthorized: true, + }) + const result = await integration.testConnection() + expect(result).toBe(true) + }) + + it("test invalid database", async () => { + const integration = new mysql.integration({ + host, + port, + user: "user", + database: "test", + password: "password", + rejectUnauthorized: true, + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: "Access denied for user 'user'@'%' to database 'test'", + }) + }) + + it("test invalid password", async () => { + const integration = new mysql.integration({ + host, + port, + user: "root", + database: "test", + password: "wrong", + rejectUnauthorized: true, + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: + "Access denied for user 'root'@'172.17.0.1' (using password: YES)", + }) + }) + }) +}) diff --git a/qa-core/src/integrations/validators/postgres.spec.ts b/qa-core/src/integrations/validators/postgres.spec.ts index 07f2b80f1a..5aa3250e2a 100644 --- a/qa-core/src/integrations/validators/postgres.spec.ts +++ b/qa-core/src/integrations/validators/postgres.spec.ts @@ -1,9 +1,7 @@ import { GenericContainer } from "testcontainers" import postgres from "../../../../packages/server/src/integrations/postgres" -import mysql from "../../../../packages/server/src/integrations/mysql" jest.unmock("pg") -jest.unmock("mysql2/promise") describe("datasource validators", () => { describe("postgres", () => { @@ -52,66 +50,4 @@ describe("datasource validators", () => { }) }) }) - - describe("mysql", () => { - let host: string - let port: number - - beforeAll(async () => { - const container = await new GenericContainer("mysql") - .withExposedPorts(3306) - .withEnv("MYSQL_ROOT_PASSWORD", "admin") - .withEnv("MYSQL_DATABASE", "db") - .withEnv("MYSQL_USER", "user") - .withEnv("MYSQL_PASSWORD", "password") - .start() - - host = container.getContainerIpAddress() - port = container.getMappedPort(3306) - }) - - it("test valid connection string", async () => { - const integration = new mysql.integration({ - host, - port, - user: "user", - database: "db", - password: "password", - rejectUnauthorized: true, - }) - const result = await integration.testConnection() - expect(result).toBe(true) - }) - - it("test invalid database", async () => { - const integration = new mysql.integration({ - host, - port, - user: "user", - database: "test", - password: "password", - rejectUnauthorized: true, - }) - const result = await integration.testConnection() - expect(result).toEqual({ - error: "Access denied for user 'user'@'%' to database 'test'", - }) - }) - - it("test invalid password", async () => { - const integration = new mysql.integration({ - host, - port, - user: "root", - database: "test", - password: "wrong", - rejectUnauthorized: true, - }) - const result = await integration.testConnection() - expect(result).toEqual({ - error: - "Access denied for user 'root'@'172.17.0.1' (using password: YES)", - }) - }) - }) })