Implement the check as part of the integration
This commit is contained in:
parent
b8d11fa351
commit
fad57db634
|
@ -7,7 +7,7 @@ import {
|
|||
|
||||
import { Database, aql } from "arangojs"
|
||||
|
||||
export interface ArangodbConfig {
|
||||
interface ArangodbConfig {
|
||||
url: string
|
||||
username: string
|
||||
password: string
|
||||
|
@ -74,6 +74,15 @@ class ArangoDBIntegration implements IntegrationBase {
|
|||
this.client = new Database(newConfig)
|
||||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
await this.client.get()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
async read(query: { sql: any }) {
|
||||
try {
|
||||
const result = await this.client.query(query.sql)
|
||||
|
@ -102,24 +111,9 @@ class ArangoDBIntegration implements IntegrationBase {
|
|||
this.client.close()
|
||||
}
|
||||
}
|
||||
|
||||
async check() {
|
||||
await this.client.get()
|
||||
}
|
||||
}
|
||||
|
||||
async function validateConnection(config: ArangodbConfig) {
|
||||
const integration = new ArangoDBIntegration(config)
|
||||
try {
|
||||
await integration.check()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
schema: SCHEMA,
|
||||
integration: ArangoDBIntegration,
|
||||
validateConnection,
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ jest.unmock("arangojs")
|
|||
|
||||
describe("datasource validators", () => {
|
||||
describe("arangodb", () => {
|
||||
const validator = integrations.getValidator[SourceName.ARANGODB]
|
||||
|
||||
let connectionSettings: {
|
||||
user: string
|
||||
password: string
|
||||
|
@ -35,37 +33,40 @@ describe("datasource validators", () => {
|
|||
})
|
||||
|
||||
it("test valid connection string", async () => {
|
||||
const result = await validator({
|
||||
const integration = new arangodb.integration({
|
||||
url: connectionSettings.url,
|
||||
username: connectionSettings.user,
|
||||
password: connectionSettings.password,
|
||||
databaseName: "",
|
||||
collection: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("test wrong password", async () => {
|
||||
const result = await validator({
|
||||
const integration = new arangodb.integration({
|
||||
url: connectionSettings.url,
|
||||
username: connectionSettings.user,
|
||||
password: "wrong",
|
||||
databaseName: "",
|
||||
collection: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({
|
||||
error: "not authorized to execute this request",
|
||||
})
|
||||
})
|
||||
|
||||
it("test wrong url", async () => {
|
||||
const result = await validator({
|
||||
const integration = new arangodb.integration({
|
||||
url: "http://not.here",
|
||||
username: connectionSettings.user,
|
||||
password: connectionSettings.password,
|
||||
databaseName: "",
|
||||
collection: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({
|
||||
error: "getaddrinfo ENOTFOUND not.here",
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue