Skip to content

Commit

Permalink
Add a few test changes
Browse files Browse the repository at this point in the history
Using database for tests and remove datetime and json from singlestore allTypes test on push
  • Loading branch information
AndriiSherman committed Nov 7, 2024
1 parent 6b8676e commit feb0e60
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 384 deletions.
65 changes: 41 additions & 24 deletions drizzle-kit/tests/push/singlestore-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function createDockerDB(): Promise<string> {

const pullStream = await docker.pull(image);
await new Promise((resolve, reject) =>
docker.modem.followProgress(pullStream, (err) => (err ? reject(err) : resolve(err)))
docker.modem.followProgress(pullStream, (err) => err ? reject(err) : resolve(err))
);

singlestoreContainer = await docker.createContainer({
Expand All @@ -40,7 +40,7 @@ async function createDockerDB(): Promise<string> {
}

beforeAll(async () => {
const connectionString = process.env.MYSQL_CONNECTION_STRING ?? await createDockerDB();
const connectionString = process.env.MYSQL_CONNECTION_STRING ?? (await createDockerDB());

const sleep = 1000;
let timeLeft = 20000;
Expand All @@ -64,6 +64,9 @@ beforeAll(async () => {
await singlestoreContainer?.stop().catch(console.error);
throw lastError;
}

await client.query('CREATE DATABASE drizzle;');
await client.query('USE drizzle;');
});

afterAll(async () => {
Expand Down Expand Up @@ -103,7 +106,7 @@ test('add check constraint to table', async () => {
type: 'create_check_constraint',
tableName: 'test',
schema: '',
data: 'some_check1;\`test\`.\`values\` < 100',
data: 'some_check1;`test`.`values` < 100',
},
{
data: "some_check2;'test' < 100",
Expand All @@ -113,7 +116,7 @@ test('add check constraint to table', async () => {
},
]);
expect(sqlStatements).toStrictEqual([
'ALTER TABLE \`test\` ADD CONSTRAINT \`some_check1\` CHECK (\`test\`.\`values\` < 100);',
'ALTER TABLE `test` ADD CONSTRAINT `some_check1` CHECK (`test`.`values` < 100);',
`ALTER TABLE \`test\` ADD CONSTRAINT \`some_check2\` CHECK ('test' < 100);`,
]);

Expand Down Expand Up @@ -158,7 +161,7 @@ test('drop check constraint to table', async () => {
},
]);
expect(sqlStatements).toStrictEqual([
'ALTER TABLE \`test\` DROP CONSTRAINT \`some_check1\`;',
'ALTER TABLE `test` DROP CONSTRAINT `some_check1`;',
`ALTER TABLE \`test\` DROP CONSTRAINT \`some_check2\`;`,
]);

Expand Down Expand Up @@ -218,7 +221,7 @@ test('create view', async () => {

expect(statements).toStrictEqual([
{
definition: 'select \`id\` from \`test\`',
definition: 'select `id` from `test`',
name: 'view',
type: 'singlestore_create_view',
replace: false,
Expand Down Expand Up @@ -265,9 +268,7 @@ test('drop view', async () => {
type: 'drop_view',
},
]);
expect(sqlStatements).toStrictEqual([
'DROP VIEW \`view\`;',
]);
expect(sqlStatements).toStrictEqual(['DROP VIEW `view`;']);
await client.query(`DROP TABLE \`test\`;`);
await client.query(`DROP VIEW \`view\`;`);
});
Expand All @@ -279,7 +280,12 @@ test('alter view ".as"', async () => {

const schema1 = {
test: table,
view: singlestoreView('view').as((qb) => qb.select().from(table).where(sql`${table.id} = 1`)),
view: singlestoreView('view').as((qb) =>
qb
.select()
.from(table)
.where(sql`${table.id} = 1`)
),
};

const schema2 = {
Expand Down Expand Up @@ -310,26 +316,37 @@ test('alter meta options with distinct in definition', async () => {

const schema1 = {
test: table,
view: singlestoreView('view').withCheckOption('cascaded').sqlSecurity('definer').algorithm('merge').as((
qb,
) => qb.selectDistinct().from(table).where(sql`${table.id} = 1`)),
view: singlestoreView('view')
.withCheckOption('cascaded')
.sqlSecurity('definer')
.algorithm('merge')
.as((qb) =>
qb
.selectDistinct()
.from(table)
.where(sql`${table.id} = 1`)
),
};

const schema2 = {
test: table,
view: singlestoreView('view').withCheckOption('cascaded').sqlSecurity('definer').algorithm('undefined').as((qb) =>
qb.selectDistinct().from(table)
),
view: singlestoreView('view')
.withCheckOption('cascaded')
.sqlSecurity('definer')
.algorithm('undefined')
.as((qb) => qb.selectDistinct().from(table)),
};

await expect(diffTestSchemasPushSingleStore(
client,
schema1,
schema2,
[],
'drizzle',
false,
)).rejects.toThrowError();
await expect(
diffTestSchemasPushSingleStore(
client,
schema1,
schema2,
[],
'drizzle',
false,
),
).rejects.toThrowError();

await client.query(`DROP TABLE \`test\`;`);
});
Loading

0 comments on commit feb0e60

Please sign in to comment.