From 33988428ea24894db285529c88821bc9b60b3297 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 15 May 2023 13:52:55 +0200 Subject: [PATCH] Split tests --- .../src/integrations/validators/couch.spec.ts | 64 +++++++++++++++++++ .../integrations/validators/postgres.spec.ts | 62 ------------------ 2 files changed, 64 insertions(+), 62 deletions(-) create mode 100644 qa-core/src/integrations/validators/couch.spec.ts diff --git a/qa-core/src/integrations/validators/couch.spec.ts b/qa-core/src/integrations/validators/couch.spec.ts new file mode 100644 index 0000000000..18fbea8c43 --- /dev/null +++ b/qa-core/src/integrations/validators/couch.spec.ts @@ -0,0 +1,64 @@ +import { GenericContainer } from "testcontainers" +import { generator } from "@budibase/backend-core/tests" + +import couchdb from "../../../../packages/server/src/integrations/couchdb" + +describe("datasource validators", () => { + describe("couchdb", () => { + let url: string + + beforeAll(async () => { + const user = generator.first() + const password = generator.hash() + + const container = await new GenericContainer("budibase/couchdb") + .withExposedPorts(5984) + .withEnv("COUCHDB_USER", user) + .withEnv("COUCHDB_PASSWORD", password) + .start() + + const host = container.getContainerIpAddress() + const port = container.getMappedPort(5984) + + await container.exec([ + `curl`, + `-u`, + `${user}:${password}`, + `-X`, + `PUT`, + `localhost:5984/db`, + ]) + url = `http://${user}:${password}@${host}:${port}` + }) + + it("test valid connection string", async () => { + const integration = new couchdb.integration({ + url, + database: "db", + }) + const result = await integration.testConnection() + expect(result).toBe(true) + }) + + it("test invalid database", async () => { + const integration = new couchdb.integration({ + url, + database: "random_db", + }) + const result = await integration.testConnection() + expect(result).toBe(false) + }) + + it("test invalid url", async () => { + const integration = new couchdb.integration({ + url: "http://invalid:123", + database: "any", + }) + const result = await integration.testConnection() + expect(result).toEqual({ + error: + "request to http://invalid:123/any failed, reason: getaddrinfo ENOTFOUND invalid", + }) + }) + }) +}) diff --git a/qa-core/src/integrations/validators/postgres.spec.ts b/qa-core/src/integrations/validators/postgres.spec.ts index 78bda902d2..5aa3250e2a 100644 --- a/qa-core/src/integrations/validators/postgres.spec.ts +++ b/qa-core/src/integrations/validators/postgres.spec.ts @@ -1,10 +1,6 @@ import { GenericContainer } from "testcontainers" import postgres from "../../../../packages/server/src/integrations/postgres" -import { generator } from "@budibase/backend-core/tests" - -import couchdb from "../../../../packages/server/src/integrations/couchdb" - jest.unmock("pg") describe("datasource validators", () => { @@ -54,62 +50,4 @@ describe("datasource validators", () => { }) }) }) - - describe("couchdb", () => { - let url: string - - beforeAll(async () => { - const user = generator.first() - const password = generator.hash() - - const container = await new GenericContainer("budibase/couchdb") - .withExposedPorts(5984) - .withEnv("COUCHDB_USER", user) - .withEnv("COUCHDB_PASSWORD", password) - .start() - - const host = container.getContainerIpAddress() - const port = container.getMappedPort(5984) - - await container.exec([ - `curl`, - `-u`, - `${user}:${password}`, - `-X`, - `PUT`, - `localhost:5984/db`, - ]) - url = `http://${user}:${password}@${host}:${port}` - }) - - it("test valid connection string", async () => { - const integration = new couchdb.integration({ - url, - database: "db", - }) - const result = await integration.testConnection() - expect(result).toBe(true) - }) - - it("test invalid database", async () => { - const integration = new couchdb.integration({ - url, - database: "random_db", - }) - const result = await integration.testConnection() - expect(result).toBe(false) - }) - - it("test invalid url", async () => { - const integration = new couchdb.integration({ - url: "http://invalid:123", - database: "any", - }) - const result = await integration.testConnection() - expect(result).toEqual({ - error: - "request to http://invalid:123/any failed, reason: getaddrinfo ENOTFOUND invalid", - }) - }) - }) })