Implement the check as part of the integration
This commit is contained in:
parent
5456866c45
commit
d656edad40
|
@ -67,6 +67,15 @@ class CouchDBIntegration implements IntegrationBase {
|
|||
this.client = dbCore.DatabaseWithConnection(config.database, config.url)
|
||||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
const result = await this.query("exists", "validation error", {})
|
||||
return result === true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
async query(
|
||||
command: string,
|
||||
errorMsg: string,
|
||||
|
@ -125,18 +134,7 @@ class CouchDBIntegration implements IntegrationBase {
|
|||
}
|
||||
}
|
||||
|
||||
async function validateConnection(config: CouchDBConfig) {
|
||||
const integration = new CouchDBIntegration(config)
|
||||
try {
|
||||
const result = await integration.query("exists", "validation error", {})
|
||||
return result === true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
schema: SCHEMA,
|
||||
integration: CouchDBIntegration,
|
||||
validateConnection,
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ 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", () => {
|
||||
|
@ -52,4 +54,62 @@ 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",
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue