Test redis
This commit is contained in:
parent
cb398dad02
commit
058ac416ea
|
@ -86,7 +86,7 @@ const SCHEMA: Integration = {
|
|||
|
||||
class RedisIntegration {
|
||||
private readonly config: RedisConfig
|
||||
private client: any
|
||||
private client
|
||||
|
||||
constructor(config: RedisConfig) {
|
||||
this.config = config
|
||||
|
@ -99,6 +99,17 @@ class RedisIntegration {
|
|||
})
|
||||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
await this.client.ping()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
} finally {
|
||||
await this.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
return this.client.quit()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
import { generator } from "@budibase/backend-core/tests"
|
||||
import redis from "../../../../integrations/redis"
|
||||
import { GenericContainer } from "testcontainers"
|
||||
|
||||
jest.unmock("pg")
|
||||
|
||||
describe("datasource validators", () => {
|
||||
describe("redis", () => {
|
||||
describe("unsecured", () => {
|
||||
let host: string
|
||||
let port: number
|
||||
|
||||
beforeAll(async () => {
|
||||
const container = await new GenericContainer("redis")
|
||||
.withExposedPorts(6379)
|
||||
.start()
|
||||
|
||||
host = container.getContainerIpAddress()
|
||||
port = container.getMappedPort(6379)
|
||||
})
|
||||
|
||||
it("test valid connection", async () => {
|
||||
const integration = new redis.integration({
|
||||
host,
|
||||
port,
|
||||
username: "",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("test invalid connection even with wrong user/password", async () => {
|
||||
const integration = new redis.integration({
|
||||
host,
|
||||
port,
|
||||
username: generator.name(),
|
||||
password: generator.hash(),
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toEqual({
|
||||
error:
|
||||
"WRONGPASS invalid username-password pair or user is disabled.",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("secured", () => {
|
||||
let host: string
|
||||
let port: number
|
||||
|
||||
beforeAll(async () => {
|
||||
const container = await new GenericContainer("redis")
|
||||
.withExposedPorts(6379)
|
||||
.withCmd(["redis-server", "--requirepass", "P@ssW0rd!"])
|
||||
.start()
|
||||
|
||||
host = container.getContainerIpAddress()
|
||||
port = container.getMappedPort(6379)
|
||||
})
|
||||
|
||||
it("test valid connection", async () => {
|
||||
const integration = new redis.integration({
|
||||
host,
|
||||
port,
|
||||
username: "",
|
||||
password: "P@ssW0rd!",
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue