1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Get tests running with SQL Server. Need to make them pass next.

This commit is contained in:
Sam Rose 2024-03-12 10:42:42 +00:00
parent 186f916b40
commit ce209a16b3
No known key found for this signature in database
3 changed files with 58 additions and 2 deletions

View file

@ -41,13 +41,15 @@ tk.freeze(timestamp)
jest.setTimeout(99999999)
jest.unmock("mysql2")
jest.unmock("mysql2/promise")
jest.unmock("mssql")
const { basicRow } = setup.structures
describe.each([
// ["internal", undefined],
// ["postgres", databaseTestProviders.postgres],
["mysql", databaseTestProviders.mysql],
// ["mysql", databaseTestProviders.mysql],
["mssql", databaseTestProviders.mssql],
])("/rows (%s)", (__, dsProvider) => {
const isInternal = !dsProvider

View file

@ -4,6 +4,7 @@ import { Datasource } from "@budibase/types"
import * as postgres from "./postgres"
import * as mongodb from "./mongodb"
import * as mysql from "./mysql"
import * as mssql from "./mssql"
import { StartedTestContainer } from "testcontainers"
jest.setTimeout(30000)
@ -14,4 +15,4 @@ export interface DatabaseProvider {
datasource(): Promise<Datasource>
}
export const databaseTestProviders = { postgres, mongodb, mysql }
export const databaseTestProviders = { postgres, mongodb, mysql, mssql }

View file

@ -0,0 +1,53 @@
import { Datasource, SourceName } from "@budibase/types"
import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
let container: StartedTestContainer | undefined
export async function start(): Promise<StartedTestContainer> {
return await new GenericContainer(
"mcr.microsoft.com/mssql/server:2022-latest"
)
.withExposedPorts(1433)
.withEnvironment({
ACCEPT_EULA: "Y",
MSSQL_SA_PASSWORD: "Password_123",
// This is important, as Microsoft allow us to use the "Developer" edition
// of SQL Server for development and testing purposes. We can't use other
// versions without a valid license, and we cannot use the Developer
// version in production.
MSSQL_PID: "Developer",
})
.withWaitStrategy(
Wait.forSuccessfulCommand(
"/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Password_123 -q 'SELECT 1'"
)
)
.start()
}
export async function datasource(): Promise<Datasource> {
if (!container) {
container = await start()
}
const host = container.getHost()
const port = container.getMappedPort(1433)
return {
type: "datasource_plus",
source: SourceName.SQL_SERVER,
plus: true,
config: {
server: host,
port,
user: "sa",
password: "Password_123",
},
}
}
export async function stop() {
if (container) {
await container.stop()
container = undefined
}
}