Use docker utils helpers
This commit is contained in:
parent
baab7d3fb5
commit
57801b5bcc
|
@ -12,13 +12,12 @@ import {
|
||||||
FieldType,
|
FieldType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
Row,
|
Row,
|
||||||
SourceName,
|
|
||||||
Table,
|
Table,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { utils } from "@budibase/backend-core"
|
import { utils } from "@budibase/backend-core"
|
||||||
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
|
import { testDatasourceConfig } from "../integrations/tests/utils"
|
||||||
|
|
||||||
const config = setup.getConfig()!
|
const config = setup.getConfig()!
|
||||||
|
|
||||||
|
@ -35,61 +34,19 @@ describe("postgres integrations", () => {
|
||||||
manyToOneRelationshipInfo: ForeignTableInfo,
|
manyToOneRelationshipInfo: ForeignTableInfo,
|
||||||
manyToManyRelationshipInfo: ForeignTableInfo
|
manyToManyRelationshipInfo: ForeignTableInfo
|
||||||
|
|
||||||
let host: string
|
let pgDatasourceConfig: Datasource
|
||||||
let port: number
|
|
||||||
const containers: StartedTestContainer[] = []
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const containerPostgres = await new GenericContainer("postgres")
|
pgDatasourceConfig = await testDatasourceConfig.postgres()
|
||||||
.withExposedPorts(5432)
|
|
||||||
.withEnv("POSTGRES_PASSWORD", "password")
|
|
||||||
.withWaitStrategy(
|
|
||||||
Wait.forLogMessage(
|
|
||||||
"PostgreSQL init process complete; ready for start up."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
host = containerPostgres.getContainerIpAddress()
|
|
||||||
port = containerPostgres.getMappedPort(5432)
|
|
||||||
|
|
||||||
await config.init()
|
await config.init()
|
||||||
const apiKey = await config.generateApiKey()
|
const apiKey = await config.generateApiKey()
|
||||||
|
|
||||||
containers.push(containerPostgres)
|
|
||||||
|
|
||||||
makeRequest = generateMakeRequest(apiKey, true)
|
makeRequest = generateMakeRequest(apiKey, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
for (let container of containers) {
|
|
||||||
await container.stop()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function pgDatasourceConfig() {
|
|
||||||
return {
|
|
||||||
datasource: {
|
|
||||||
type: "datasource",
|
|
||||||
source: SourceName.POSTGRES,
|
|
||||||
plus: true,
|
|
||||||
config: {
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
database: "postgres",
|
|
||||||
user: "postgres",
|
|
||||||
password: "password",
|
|
||||||
schema: "public",
|
|
||||||
ssl: false,
|
|
||||||
rejectUnauthorized: false,
|
|
||||||
ca: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
postgresDatasource = await config.createDatasource(pgDatasourceConfig())
|
postgresDatasource = await config.api.datasource.create(pgDatasourceConfig)
|
||||||
|
|
||||||
async function createAuxTable(prefix: string) {
|
async function createAuxTable(prefix: string) {
|
||||||
return await config.createTable({
|
return await config.createTable({
|
||||||
|
@ -357,9 +314,9 @@ describe("postgres integrations", () => {
|
||||||
config: {
|
config: {
|
||||||
ca: false,
|
ca: false,
|
||||||
database: "postgres",
|
database: "postgres",
|
||||||
host,
|
host: postgresDatasource.config!.host,
|
||||||
password: "--secret-value--",
|
password: "--secret-value--",
|
||||||
port,
|
port: postgresDatasource.config!.port,
|
||||||
rejectUnauthorized: false,
|
rejectUnauthorized: false,
|
||||||
schema: "public",
|
schema: "public",
|
||||||
ssl: false,
|
ssl: false,
|
||||||
|
@ -1046,24 +1003,21 @@ describe("postgres integrations", () => {
|
||||||
|
|
||||||
describe("POST /api/datasources/verify", () => {
|
describe("POST /api/datasources/verify", () => {
|
||||||
it("should be able to verify the connection", async () => {
|
it("should be able to verify the connection", async () => {
|
||||||
const config = pgDatasourceConfig()
|
const response = await config.api.datasource.verify({
|
||||||
const response = await makeRequest(
|
datasource: pgDatasourceConfig,
|
||||||
"post",
|
})
|
||||||
"/api/datasources/verify",
|
|
||||||
config
|
|
||||||
)
|
|
||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
expect(response.body.connected).toBe(true)
|
expect(response.body.connected).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should state an invalid datasource cannot connect", async () => {
|
it("should state an invalid datasource cannot connect", async () => {
|
||||||
const config = pgDatasourceConfig()
|
const response = await config.api.datasource.verify({
|
||||||
config.datasource.config.password = "wrongpassword"
|
datasource: {
|
||||||
const response = await makeRequest(
|
...pgDatasourceConfig,
|
||||||
"post",
|
config: { ...pgDatasourceConfig.config, password: "wrongpassword" },
|
||||||
"/api/datasources/verify",
|
},
|
||||||
config
|
})
|
||||||
)
|
|
||||||
expect(response.status).toBe(200)
|
expect(response.status).toBe(200)
|
||||||
expect(response.body.connected).toBe(false)
|
expect(response.body.connected).toBe(false)
|
||||||
expect(response.body.error).toBeDefined()
|
expect(response.body.error).toBeDefined()
|
||||||
|
|
Loading…
Reference in New Issue