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