Integrate Elasticsearch as a test datasource.
This commit is contained in:
parent
f484673667
commit
1c23509839
|
@ -155,7 +155,18 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
datasource:
|
datasource:
|
||||||
[mssql, mysql, postgres, postgres_legacy, mongodb, mariadb, oracle, sqs, none]
|
[
|
||||||
|
mssql,
|
||||||
|
mysql,
|
||||||
|
postgres,
|
||||||
|
postgres_legacy,
|
||||||
|
mongodb,
|
||||||
|
mariadb,
|
||||||
|
oracle,
|
||||||
|
sqs,
|
||||||
|
elasticsearch,
|
||||||
|
none,
|
||||||
|
]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
@ -192,6 +203,8 @@ jobs:
|
||||||
docker pull budibase/oracle-database:23.2-slim-faststart
|
docker pull budibase/oracle-database:23.2-slim-faststart
|
||||||
elif [ "${{ matrix.datasource }}" == "postgres_legacy" ]; then
|
elif [ "${{ matrix.datasource }}" == "postgres_legacy" ]; then
|
||||||
docker pull postgres:9.5.25
|
docker pull postgres:9.5.25
|
||||||
|
elif [ "${{ matrix.datasource }}" == "elasticsearch" ]; then
|
||||||
|
docker pull elasticsearch@${{ steps.dotenv.outputs.ELASTICSEARCH_SHA }}
|
||||||
fi
|
fi
|
||||||
docker pull minio/minio &
|
docker pull minio/minio &
|
||||||
docker pull redis &
|
docker pull redis &
|
||||||
|
|
|
@ -165,7 +165,8 @@ describe("/datasources", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({
|
const descriptions = datasourceDescribe({
|
||||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
plus: true,
|
||||||
|
exclude: [DatabaseName.SQS],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
|
@ -590,7 +591,8 @@ if (descriptions.length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const datasources = datasourceDescribe({
|
const datasources = datasourceDescribe({
|
||||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS, DatabaseName.ORACLE],
|
plus: true,
|
||||||
|
exclude: [DatabaseName.SQS, DatabaseName.ORACLE],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (datasources.length) {
|
if (datasources.length) {
|
||||||
|
|
|
@ -9,7 +9,8 @@ import { Knex } from "knex"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({
|
const descriptions = datasourceDescribe({
|
||||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
plus: true,
|
||||||
|
exclude: [DatabaseName.SQS],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
|
|
||||||
import {
|
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||||
DatabaseName,
|
|
||||||
datasourceDescribe,
|
|
||||||
} from "../../../integrations/tests/utils"
|
|
||||||
|
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
import emitter from "../../../../src/events"
|
import emitter from "../../../../src/events"
|
||||||
|
@ -80,7 +77,7 @@ function encodeJS(binding: string) {
|
||||||
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
const descriptions = datasourceDescribe({ plus: true })
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
describe.each(descriptions)(
|
describe.each(descriptions)(
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||||
import {
|
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||||
DatabaseName,
|
|
||||||
datasourceDescribe,
|
|
||||||
} from "../../../integrations/tests/utils"
|
|
||||||
import {
|
import {
|
||||||
context,
|
context,
|
||||||
db as dbCore,
|
db as dbCore,
|
||||||
|
@ -60,7 +57,7 @@ jest.mock("@budibase/pro", () => ({
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
const descriptions = datasourceDescribe({ plus: true })
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
describe.each(descriptions)(
|
describe.each(descriptions)(
|
||||||
|
|
|
@ -28,17 +28,14 @@ import * as setup from "./utilities"
|
||||||
import * as uuid from "uuid"
|
import * as uuid from "uuid"
|
||||||
|
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import {
|
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||||
DatabaseName,
|
|
||||||
datasourceDescribe,
|
|
||||||
} from "../../../integrations/tests/utils"
|
|
||||||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||||
import timekeeper from "timekeeper"
|
import timekeeper from "timekeeper"
|
||||||
|
|
||||||
const { basicTable } = setup.structures
|
const { basicTable } = setup.structures
|
||||||
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
|
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
const descriptions = datasourceDescribe({ plus: true })
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
describe.each(descriptions)(
|
describe.each(descriptions)(
|
||||||
|
|
|
@ -37,17 +37,14 @@ import {
|
||||||
ViewV2Type,
|
ViewV2Type,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import {
|
import { datasourceDescribe } from "../../../integrations/tests/utils"
|
||||||
DatabaseName,
|
|
||||||
datasourceDescribe,
|
|
||||||
} from "../../../integrations/tests/utils"
|
|
||||||
import merge from "lodash/merge"
|
import merge from "lodash/merge"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import { context, db, events, roles, setEnv } from "@budibase/backend-core"
|
import { context, db, events, roles, setEnv } from "@budibase/backend-core"
|
||||||
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/openai"
|
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/openai"
|
||||||
import nock from "nock"
|
import nock from "nock"
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
const descriptions = datasourceDescribe({ plus: true })
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
describe.each(descriptions)(
|
describe.each(descriptions)(
|
||||||
|
|
|
@ -9,7 +9,8 @@ import { generator } from "@budibase/backend-core/tests"
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
|
|
||||||
const descriptions = datasourceDescribe({
|
const descriptions = datasourceDescribe({
|
||||||
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
plus: true,
|
||||||
|
exclude: [DatabaseName.SQS],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
|
|
|
@ -2,8 +2,12 @@ import { Datasource } from "@budibase/types"
|
||||||
import { ElasticsearchConfig, ElasticSearchIntegration } from "../elasticsearch"
|
import { ElasticsearchConfig, ElasticSearchIntegration } from "../elasticsearch"
|
||||||
import * as elasticsearch from "../tests/utils/elasticsearch"
|
import * as elasticsearch from "../tests/utils/elasticsearch"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
import { DatabaseName, datasourceDescribe } from "./utils"
|
||||||
|
|
||||||
describe("Elasticsearch Integration", () => {
|
const describes = datasourceDescribe({ only: [DatabaseName.ELASTICSEARCH] })
|
||||||
|
|
||||||
|
if (describes.length) {
|
||||||
|
describe.each(describes)("Elasticsearch Integration", () => {
|
||||||
let datasource: Datasource
|
let datasource: Datasource
|
||||||
let integration: ElasticSearchIntegration
|
let integration: ElasticSearchIntegration
|
||||||
|
|
||||||
|
@ -74,3 +78,4 @@ describe("Elasticsearch Integration", () => {
|
||||||
expect(records).toEqual([])
|
expect(records).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as mysql from "./mysql"
|
||||||
import * as mssql from "./mssql"
|
import * as mssql from "./mssql"
|
||||||
import * as mariadb from "./mariadb"
|
import * as mariadb from "./mariadb"
|
||||||
import * as oracle from "./oracle"
|
import * as oracle from "./oracle"
|
||||||
|
import * as elasticsearch from "./elasticsearch"
|
||||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
@ -23,22 +24,32 @@ export enum DatabaseName {
|
||||||
MARIADB = "mariadb",
|
MARIADB = "mariadb",
|
||||||
ORACLE = "oracle",
|
ORACLE = "oracle",
|
||||||
SQS = "sqs",
|
SQS = "sqs",
|
||||||
|
ELASTICSEARCH = "elasticsearch",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DATASOURCE_PLUS = [
|
||||||
|
DatabaseName.POSTGRES,
|
||||||
|
DatabaseName.POSTGRES_LEGACY,
|
||||||
|
DatabaseName.MYSQL,
|
||||||
|
DatabaseName.SQL_SERVER,
|
||||||
|
DatabaseName.MARIADB,
|
||||||
|
DatabaseName.ORACLE,
|
||||||
|
DatabaseName.SQS,
|
||||||
|
]
|
||||||
|
|
||||||
const providers: Record<DatabaseName, DatasourceProvider> = {
|
const providers: Record<DatabaseName, DatasourceProvider> = {
|
||||||
|
// datasource_plus entries
|
||||||
[DatabaseName.POSTGRES]: postgres.getDatasource,
|
[DatabaseName.POSTGRES]: postgres.getDatasource,
|
||||||
[DatabaseName.POSTGRES_LEGACY]: postgres.getLegacyDatasource,
|
[DatabaseName.POSTGRES_LEGACY]: postgres.getLegacyDatasource,
|
||||||
[DatabaseName.MONGODB]: mongodb.getDatasource,
|
|
||||||
[DatabaseName.MYSQL]: mysql.getDatasource,
|
[DatabaseName.MYSQL]: mysql.getDatasource,
|
||||||
[DatabaseName.SQL_SERVER]: mssql.getDatasource,
|
[DatabaseName.SQL_SERVER]: mssql.getDatasource,
|
||||||
[DatabaseName.MARIADB]: mariadb.getDatasource,
|
[DatabaseName.MARIADB]: mariadb.getDatasource,
|
||||||
[DatabaseName.ORACLE]: oracle.getDatasource,
|
[DatabaseName.ORACLE]: oracle.getDatasource,
|
||||||
[DatabaseName.SQS]: async () => undefined,
|
[DatabaseName.SQS]: async () => undefined,
|
||||||
}
|
|
||||||
|
|
||||||
export interface DatasourceDescribeOpts {
|
// rest
|
||||||
only?: DatabaseName[]
|
[DatabaseName.ELASTICSEARCH]: elasticsearch.getDatasource,
|
||||||
exclude?: DatabaseName[]
|
[DatabaseName.MONGODB]: mongodb.getDatasource,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DatasourceDescribeReturnPromise {
|
export interface DatasourceDescribeReturnPromise {
|
||||||
|
@ -103,6 +114,20 @@ function createDummyTest() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OnlyOpts {
|
||||||
|
only: DatabaseName[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlusOpts {
|
||||||
|
plus: true
|
||||||
|
exclude?: DatabaseName[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DatasourceDescribeOpts = OnlyOpts | PlusOpts
|
||||||
|
|
||||||
|
// If you ever want to rename this function, be mindful that you will also need
|
||||||
|
// to modify src/tests/filters/index.js to make sure that we're correctly
|
||||||
|
// filtering datasource/non-datasource tests in CI.
|
||||||
export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
||||||
// tests that call this need a lot longer timeouts
|
// tests that call this need a lot longer timeouts
|
||||||
jest.setTimeout(120000)
|
jest.setTimeout(120000)
|
||||||
|
@ -111,17 +136,15 @@ export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
||||||
createDummyTest()
|
createDummyTest()
|
||||||
}
|
}
|
||||||
|
|
||||||
const { only, exclude } = opts
|
let databases: DatabaseName[] = []
|
||||||
|
if ("only" in opts) {
|
||||||
if (only && exclude) {
|
databases = opts.only
|
||||||
throw new Error("you can only supply one of 'only' or 'exclude'")
|
} else if ("plus" in opts) {
|
||||||
}
|
databases = Object.values(DatabaseName)
|
||||||
|
.filter(db => DATASOURCE_PLUS.includes(db))
|
||||||
let databases = Object.values(DatabaseName)
|
.filter(db => !opts.exclude?.includes(db))
|
||||||
if (only) {
|
} else {
|
||||||
databases = only
|
throw new Error("invalid options")
|
||||||
} else if (exclude) {
|
|
||||||
databases = databases.filter(db => !exclude.includes(db))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.DATASOURCE) {
|
if (process.env.DATASOURCE) {
|
||||||
|
@ -156,6 +179,7 @@ export function datasourceDescribe(opts: DatasourceDescribeOpts) {
|
||||||
isMSSQL: dbName === DatabaseName.SQL_SERVER,
|
isMSSQL: dbName === DatabaseName.SQL_SERVER,
|
||||||
isOracle: dbName === DatabaseName.ORACLE,
|
isOracle: dbName === DatabaseName.ORACLE,
|
||||||
isMariaDB: dbName === DatabaseName.MARIADB,
|
isMariaDB: dbName === DatabaseName.MARIADB,
|
||||||
|
isElasticsearch: dbName === DatabaseName.ELASTICSEARCH,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,16 +10,13 @@ import {
|
||||||
import { search } from "../../../../../sdk/app/rows/search"
|
import { search } from "../../../../../sdk/app/rows/search"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
import {
|
import { datasourceDescribe } from "../../../../../integrations/tests/utils"
|
||||||
DatabaseName,
|
|
||||||
datasourceDescribe,
|
|
||||||
} from "../../../../../integrations/tests/utils"
|
|
||||||
import { tableForDatasource } from "../../../../../tests/utilities/structures"
|
import { tableForDatasource } from "../../../../../tests/utilities/structures"
|
||||||
|
|
||||||
// These test cases are only for things that cannot be tested through the API
|
// These test cases are only for things that cannot be tested through the API
|
||||||
// (e.g. limiting searches to returning specific fields). If it's possible to
|
// (e.g. limiting searches to returning specific fields). If it's possible to
|
||||||
// test through the API, it should be done there instead.
|
// test through the API, it should be done there instead.
|
||||||
const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
const descriptions = datasourceDescribe({ plus: true })
|
||||||
|
|
||||||
if (descriptions.length) {
|
if (descriptions.length) {
|
||||||
describe.each(descriptions)(
|
describe.each(descriptions)(
|
||||||
|
|
Loading…
Reference in New Issue