chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import {
|
||||
countFields,
|
||||
doltBranchFields,
|
||||
doltCheckoutFields,
|
||||
doltStatusFields,
|
||||
doltCommitFields,
|
||||
} from "../fields.js";
|
||||
import { branchesMatcher } from "./matchers.js";
|
||||
import { dbName } from "../helpers.js";
|
||||
|
||||
export const branchTests = [
|
||||
{
|
||||
q: `SELECT DOLT_BRANCH($1::text, $2::text)`, // TODO: Should work without casts
|
||||
p: ["mybranch", "main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_branch: ["0"] }],
|
||||
fields: doltBranchFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/mybranch';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `create table test (pk int, "value" int, primary key(pk));`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "public.test",
|
||||
staged: false,
|
||||
status: "new table",
|
||||
},
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-Am', $1::text, '--author', $2::text);`,
|
||||
p: ["Create table test", "Dolt <dolt@dolthub.com>"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.branches LIMIT 200`,
|
||||
res: {
|
||||
rows: [
|
||||
{
|
||||
name: "main",
|
||||
hash: "",
|
||||
latest_committer: "postgres",
|
||||
latest_committer_email: "postgres@127.0.0.1",
|
||||
latest_commit_date: "",
|
||||
latest_commit_message: "CREATE DATABASE",
|
||||
remote: "",
|
||||
branch: "",
|
||||
dirty: 1,
|
||||
},
|
||||
{
|
||||
name: "mybranch",
|
||||
hash: "",
|
||||
latest_committer: "Dolt",
|
||||
latest_committer_email: "dolt@dolthub.com",
|
||||
latest_commit_date: "",
|
||||
latest_commit_message: "Create table test",
|
||||
remote: "",
|
||||
branch: "",
|
||||
dirty: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
matcher: branchesMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_CHECKOUT('-b', $1::text)`,
|
||||
p: ["branch-to-delete"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_checkout: ["0", "Switched to branch 'branch-to-delete'"] }],
|
||||
fields: doltCheckoutFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT COUNT(*) FROM dolt.branches LIMIT 200`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ count: "3" }],
|
||||
fields: countFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/main';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_BRANCH('-D', $1::text)`,
|
||||
p: ["branch-to-delete"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_branch: ["0"] }],
|
||||
fields: doltBranchFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT COUNT(*) FROM dolt.branches LIMIT 200`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ count: "2" }],
|
||||
fields: countFields,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,86 @@
|
||||
import { doltCleanFields } from "../fields.js";
|
||||
import { dbName } from "../helpers.js";
|
||||
|
||||
export const databaseTests = [
|
||||
{
|
||||
q: `USE '${dbName}/main';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_CLEAN('test_table')`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_clean: ["0"] }],
|
||||
fields: doltCleanFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT datname FROM pg_database;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [{ datname: dbName }, { datname: `${dbName}/main` }],
|
||||
fields: [
|
||||
{
|
||||
name: "datname",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 19,
|
||||
dataTypeSize: 64,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `CREATE DATABASE "new_db";`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT datname FROM pg_database;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 3,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ datname: "new_db" },
|
||||
{ datname: dbName },
|
||||
{ datname: `${dbName}/main` },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
name: "datname",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 19,
|
||||
dataTypeSize: 64,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT dolt_version();`,
|
||||
res: [{ "dolt_version()": "0.0.0" }],
|
||||
matcher: (data) => {
|
||||
return data.rows[0].dolt_version.length > 0;
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,780 @@
|
||||
import {
|
||||
doltCommitFields,
|
||||
doltDiffStatFields,
|
||||
doltDiffSummaryFields,
|
||||
doltSchemaDiffFields,
|
||||
doltStatusFields,
|
||||
pgTablesFields,
|
||||
} from "../fields.js";
|
||||
import { diffRowsMatcher, patchRowsMatcher } from "./matchers.js";
|
||||
|
||||
export const diffTests = [
|
||||
{
|
||||
q: "UPDATE test SET value=1 WHERE pk=0",
|
||||
res: {
|
||||
command: "UPDATE",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "DROP TABLE test_info",
|
||||
res: {
|
||||
command: "DROP",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `CREATE SCHEMA anotherschema;`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `create table anotherschema.testanother (pk int, "value" int, primary key(pk));`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "INSERT INTO anotherschema.testanother VALUES (1, 2)",
|
||||
res: {
|
||||
command: "INSERT",
|
||||
rowCount: 1,
|
||||
oid: 0,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status ORDER BY table_name;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 5,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_name: "anotherschema", staged: false, status: "new schema" },
|
||||
{
|
||||
table_name: "anotherschema.testanother",
|
||||
staged: false,
|
||||
status: "new table",
|
||||
},
|
||||
{
|
||||
table_name: "public.dolt_schemas",
|
||||
staged: false,
|
||||
status: "new table",
|
||||
},
|
||||
{ table_name: "public.test", staged: false, status: "modified" },
|
||||
{ table_name: "public.test_info", staged: false, status: "deleted" },
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING') ORDER BY to_table_name;", // TODO: Prepared not working
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test_info",
|
||||
to_table_name: "",
|
||||
diff_type: "dropped",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "anotherschema.testanother",
|
||||
diff_type: "added",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "public.dolt_schemas",
|
||||
diff_type: "added",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "public.test",
|
||||
to_table_name: "public.test",
|
||||
diff_type: "modified",
|
||||
data_change: 1,
|
||||
schema_change: 0,
|
||||
},
|
||||
],
|
||||
fields: doltDiffSummaryFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING', 'test')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test",
|
||||
to_table_name: "public.test",
|
||||
diff_type: "modified",
|
||||
data_change: 1,
|
||||
schema_change: 0,
|
||||
},
|
||||
],
|
||||
fields: doltDiffSummaryFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
// TODO: What if a table with same name but different schema exists in different schema?
|
||||
q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING', 'testanother')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "anotherschema.testanother",
|
||||
diff_type: "added",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
],
|
||||
fields: doltDiffSummaryFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING') ORDER BY table_name",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "anotherschema.testanother",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "1",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "2",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "0",
|
||||
new_row_count: "1",
|
||||
old_cell_count: "0",
|
||||
new_cell_count: "2",
|
||||
},
|
||||
{
|
||||
table_name: "public.dolt_schemas",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "1",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "5",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "0",
|
||||
new_row_count: "1",
|
||||
old_cell_count: "0",
|
||||
new_cell_count: "5",
|
||||
},
|
||||
{
|
||||
table_name: "public.test",
|
||||
rows_unmodified: "2",
|
||||
rows_added: "0",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "1",
|
||||
cells_added: "0",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "1",
|
||||
old_row_count: "3",
|
||||
new_row_count: "3",
|
||||
old_cell_count: "6",
|
||||
new_cell_count: "6",
|
||||
},
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "0",
|
||||
rows_deleted: "1",
|
||||
rows_modified: "0",
|
||||
cells_added: "0",
|
||||
cells_deleted: "3",
|
||||
cells_modified: "0",
|
||||
old_row_count: "1",
|
||||
new_row_count: "0",
|
||||
old_cell_count: "3",
|
||||
new_cell_count: "0",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING', 'test_info')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "0",
|
||||
rows_deleted: "1",
|
||||
rows_modified: "0",
|
||||
cells_added: "0",
|
||||
cells_deleted: "3",
|
||||
cells_modified: "0",
|
||||
old_row_count: "1",
|
||||
new_row_count: "0",
|
||||
old_cell_count: "3",
|
||||
new_cell_count: "0",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING', 'testanother')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "anotherschema.testanother",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "1",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "2",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "0",
|
||||
new_row_count: "1",
|
||||
old_cell_count: "0",
|
||||
new_cell_count: "2",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'test') ORDER BY to_pk ASC, from_pk ASC LIMIT 10 OFFSET 0",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
to_pk: 0,
|
||||
to_value: 1,
|
||||
to_commit: "WORKING",
|
||||
to_commit_date: "2023-03-09T07:44:47.670Z",
|
||||
from_pk: 0,
|
||||
from_value: 0,
|
||||
from_commit: "HEAD",
|
||||
from_commit_date: "2023-03-09T07:44:47.488Z",
|
||||
diff_type: "modified",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: diffRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'test_info') ORDER BY to_id ASC, from_id ASC LIMIT 10 OFFSET 0",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
to_id: null,
|
||||
to_info: null,
|
||||
to_test_pk: null,
|
||||
to_commit: "WORKING",
|
||||
to_commit_date: "2023-03-09T07:53:48.614Z",
|
||||
from_id: 1,
|
||||
from_info: "info about test pk 0",
|
||||
from_test_pk: 0,
|
||||
from_commit: "HEAD",
|
||||
from_commit_date: "2023-03-09T07:53:48.284Z",
|
||||
diff_type: "removed",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: diffRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'testanother') ORDER BY to_pk ASC, from_pk ASC LIMIT 10 OFFSET 0",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
to_pk: 1,
|
||||
to_value: 2,
|
||||
to_commit: "WORKING",
|
||||
to_commit_date: "2024-10-03T04:33:43.486Z",
|
||||
from_pk: null,
|
||||
from_value: null,
|
||||
from_commit: "HEAD",
|
||||
from_commit_date: "2024-10-03T04:33:43.430Z",
|
||||
diff_type: "added",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: diffRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'dolt_schemas') ORDER BY to_name ASC, from_name ASC LIMIT 10 OFFSET 0",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
to_type: "view",
|
||||
to_name: "myview",
|
||||
to_fragment: "CREATE VIEW myview AS SELECT * FROM test",
|
||||
to_extra: { CreatedAt: 0 },
|
||||
to_sql_mode:
|
||||
"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES",
|
||||
to_commit: "WORKING",
|
||||
to_commit_date: "2023-03-09T07:56:29.035Z",
|
||||
from_type: null,
|
||||
from_name: null,
|
||||
from_fragment: null,
|
||||
from_extra: null,
|
||||
from_sql_mode: null,
|
||||
from_commit: "HEAD",
|
||||
from_commit_date: "2023-03-09T07:56:28.841Z",
|
||||
diff_type: "added",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: diffRowsMatcher,
|
||||
},
|
||||
{
|
||||
skip: true, // TODO: Order is not consistent
|
||||
q: "SELECT * FROM DOLT_PATCH('HEAD', 'WORKING') WHERE diff_type = 'schema'",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 3,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
statement_order: "1",
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "WORKING",
|
||||
table_name: "test_info",
|
||||
diff_type: "schema",
|
||||
statement: "DROP TABLE `test_info`;",
|
||||
},
|
||||
// TODO: Should `CREATE SCHEMA` statement be included here?
|
||||
{
|
||||
statement_order: "2",
|
||||
from_commit_hash: "r6g8g61k89dpgb3cuks70jfnavr6b1q0",
|
||||
to_commit_hash: "WORKING",
|
||||
table_name: "testanother",
|
||||
diff_type: "schema",
|
||||
statement:
|
||||
"CREATE TABLE `testanother` (\n" +
|
||||
" `pk` integer NOT NULL,\n" +
|
||||
" `value` integer,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
{
|
||||
statement_order: "4", // TODO: Why is this 4?
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "WORKING",
|
||||
table_name: "dolt_schemas",
|
||||
diff_type: "schema",
|
||||
statement:
|
||||
"CREATE TABLE `dolt_schemas` (\n" + // TODO: No backticks
|
||||
" `type` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `name` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `fragment` longtext,\n" +
|
||||
" `extra` json,\n" +
|
||||
" `sql_mode` varchar(256) COLLATE utf8mb4_0900_ai_ci,\n" +
|
||||
" PRIMARY KEY (`type`,`name`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: patchRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_PATCH('HEAD', 'WORKING', 'test_info') WHERE diff_type = 'schema'",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
statement_order: "1",
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "WORKING",
|
||||
table_name: "public.test_info",
|
||||
diff_type: "schema",
|
||||
statement: "DROP TABLE `test_info`;", // TODO: No backticks
|
||||
},
|
||||
],
|
||||
},
|
||||
matcher: patchRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING') ORDER BY to_table_name;",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 3,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test_info",
|
||||
to_table_name: "",
|
||||
from_create_statement:
|
||||
"CREATE TABLE `test_info` (\n" + // TODO: No backticks
|
||||
" `id` integer NOT NULL,\n" +
|
||||
" `info` varchar(255),\n" +
|
||||
" `test_pk` integer,\n" +
|
||||
" PRIMARY KEY (`id`),\n" +
|
||||
" KEY `test_info_test_pk_fkey` (`test_pk`),\n" +
|
||||
" CONSTRAINT `test_info_test_pk_fkey` FOREIGN KEY (`test_pk`) REFERENCES `test` (`pk`) ON DELETE NO ACTION ON UPDATE NO ACTION\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
to_create_statement: "",
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "anotherschema.testanother",
|
||||
from_create_statement: "",
|
||||
to_create_statement:
|
||||
"CREATE TABLE `testanother` (\n" +
|
||||
" `pk` integer NOT NULL,\n" +
|
||||
" `value` integer,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "public.dolt_schemas",
|
||||
from_create_statement: "",
|
||||
to_create_statement:
|
||||
"CREATE TABLE `dolt_schemas` (\n" + // TODO: No backticks
|
||||
" `type` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `name` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `fragment` longtext,\n" +
|
||||
" `extra` json,\n" +
|
||||
" `sql_mode` varchar(256) COLLATE utf8mb4_0900_ai_ci,\n" +
|
||||
" PRIMARY KEY (`type`,`name`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
],
|
||||
fields: doltSchemaDiffFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING', 'test_info')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test_info",
|
||||
to_table_name: "",
|
||||
from_create_statement:
|
||||
"CREATE TABLE `test_info` (\n" + // TODO: No backticks
|
||||
" `id` integer NOT NULL,\n" +
|
||||
" `info` varchar(255),\n" +
|
||||
" `test_pk` integer,\n" +
|
||||
" PRIMARY KEY (`id`),\n" +
|
||||
" KEY `test_info_test_pk_fkey` (`test_pk`),\n" +
|
||||
" CONSTRAINT `test_info_test_pk_fkey` FOREIGN KEY (`test_pk`) REFERENCES `test` (`pk`) ON DELETE NO ACTION ON UPDATE NO ACTION\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
to_create_statement: "",
|
||||
},
|
||||
],
|
||||
fields: doltSchemaDiffFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING', 'testanother')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "anotherschema.testanother",
|
||||
from_create_statement: "",
|
||||
to_create_statement:
|
||||
"CREATE TABLE `testanother` (\n" +
|
||||
" `pk` integer NOT NULL,\n" +
|
||||
" `value` integer,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
],
|
||||
fields: doltSchemaDiffFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Make some changes on branch"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
|
||||
// Three dot
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_summary('main...HEAD') ORDER BY to_table_name",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test_info",
|
||||
to_table_name: "",
|
||||
diff_type: "dropped",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "anotherschema.testanother",
|
||||
diff_type: "added",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "",
|
||||
to_table_name: "public.dolt_schemas",
|
||||
diff_type: "added",
|
||||
data_change: 1,
|
||||
schema_change: 1,
|
||||
},
|
||||
{
|
||||
from_table_name: "public.test",
|
||||
to_table_name: "public.test",
|
||||
diff_type: "modified",
|
||||
data_change: 1,
|
||||
schema_change: 0,
|
||||
},
|
||||
],
|
||||
fields: doltDiffSummaryFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_summary('main...HEAD', 'test')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
from_table_name: "public.test",
|
||||
to_table_name: "public.test",
|
||||
diff_type: "modified",
|
||||
data_change: 1,
|
||||
schema_change: 0,
|
||||
},
|
||||
],
|
||||
fields: doltDiffSummaryFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('main...HEAD') ORDER BY table_name;",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "anotherschema.testanother",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "1",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "2",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "0",
|
||||
new_row_count: "1",
|
||||
old_cell_count: "0",
|
||||
new_cell_count: "2",
|
||||
},
|
||||
{
|
||||
table_name: "public.dolt_schemas",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "1",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "5",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "0",
|
||||
new_row_count: "1",
|
||||
old_cell_count: "0",
|
||||
new_cell_count: "5",
|
||||
},
|
||||
{
|
||||
table_name: "public.test",
|
||||
rows_unmodified: "2",
|
||||
rows_added: "0",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "1",
|
||||
cells_added: "0",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "1",
|
||||
old_row_count: "3",
|
||||
new_row_count: "3",
|
||||
old_cell_count: "6",
|
||||
new_cell_count: "6",
|
||||
},
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "0",
|
||||
rows_deleted: "1",
|
||||
rows_modified: "0",
|
||||
cells_added: "0",
|
||||
cells_deleted: "3",
|
||||
cells_modified: "0",
|
||||
old_row_count: "1",
|
||||
new_row_count: "0",
|
||||
old_cell_count: "3",
|
||||
new_cell_count: "0",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('main...HEAD', 'test_info')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: "0",
|
||||
rows_added: "0",
|
||||
rows_deleted: "1",
|
||||
rows_modified: "0",
|
||||
cells_added: "0",
|
||||
cells_deleted: "3",
|
||||
cells_modified: "0",
|
||||
old_row_count: "1",
|
||||
new_row_count: "0",
|
||||
old_cell_count: "3",
|
||||
new_cell_count: "0",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
skip: true, // TODO: Order not consistent
|
||||
q: "SELECT * FROM DOLT_PATCH('main...HEAD') WHERE diff_type = 'schema'",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
statement_order: "1",
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "",
|
||||
table_name: "public.test_info",
|
||||
diff_type: "schema",
|
||||
statement: "DROP TABLE `test_info`;",
|
||||
},
|
||||
{
|
||||
statement_order: "2",
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "",
|
||||
table_name: "anotherschema.testanother",
|
||||
diff_type: "schema",
|
||||
statement:
|
||||
"CREATE TABLE `testanother` (\n" +
|
||||
" `pk` integer NOT NULL,\n" +
|
||||
" `value` integer,\n" +
|
||||
" PRIMARY KEY (`pk`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
// TODO: `CREATE SCHEMA` here?
|
||||
{
|
||||
statement_order: "4", // TODO: why
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "",
|
||||
table_name: "public.dolt_schemas",
|
||||
diff_type: "schema",
|
||||
statement:
|
||||
"CREATE TABLE `dolt_schemas` (\n" +
|
||||
" `type` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `name` varchar(64) COLLATE utf8mb4_0900_ai_ci NOT NULL,\n" +
|
||||
" `fragment` longtext,\n" +
|
||||
" `extra` json,\n" +
|
||||
" `sql_mode` varchar(256) COLLATE utf8mb4_0900_ai_ci,\n" +
|
||||
" PRIMARY KEY (`type`,`name`)\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: patchRowsMatcher,
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM DOLT_PATCH('main...HEAD', 'test_info') WHERE diff_type = 'schema'",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
statement_order: "1",
|
||||
from_commit_hash: "",
|
||||
to_commit_hash: "",
|
||||
table_name: "public.test_info",
|
||||
diff_type: "schema",
|
||||
statement: "DROP TABLE `test_info`;",
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: patchRowsMatcher,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,157 @@
|
||||
import {
|
||||
doltCommitFields,
|
||||
doltDocsFields,
|
||||
doltStatusFields,
|
||||
} from "../fields.js";
|
||||
|
||||
const readmeText = `# README
|
||||
## My List
|
||||
|
||||
- Item 1
|
||||
- Item 2
|
||||
`;
|
||||
|
||||
const updatedReadmeText = `${readmeText}-Item 3`;
|
||||
|
||||
export const docsTests = [
|
||||
{
|
||||
q: "select * from dolt.docs",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "INSERT INTO dolt.docs VALUES ($1, $2);",
|
||||
p: ["README.md", readmeText],
|
||||
res: {
|
||||
command: "INSERT",
|
||||
rowCount: 1,
|
||||
oid: 0,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `select * from dolt.docs where doc_name=$1`,
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ doc_name: "README.md", doc_text: readmeText }],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "INSERT INTO dolt.docs VALUES ($1, $2) ON CONFLICT (doc_name) DO UPDATE SET doc_text = $2",
|
||||
p: ["README.md", updatedReadmeText],
|
||||
res: {
|
||||
command: "INSERT",
|
||||
rowCount: 2, // TODO: This should be 1, but there's a bug in the GMS iterators that overcounts
|
||||
oid: 0,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `select * from dolt.docs where doc_name=$1`,
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ doc_name: "README.md", doc_text: updatedReadmeText }],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ table_name: "dolt.docs", staged: false, status: "new table" }],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Add dolt.docs table"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `select * from dolt.docs where doc_name=$1`,
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ doc_name: "README.md", doc_text: updatedReadmeText }],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "DELETE FROM dolt.docs WHERE doc_name=$1",
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "DELETE",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `select * from dolt.docs where doc_name=$1`,
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SET SEARCH_PATH = 'public,';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `select * from dolt.docs where doc_name=$1`,
|
||||
p: ["README.md"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltDocsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Remove README"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,75 @@
|
||||
import fs from "fs";
|
||||
import { pipeline } from "stream/promises";
|
||||
import { from as copyFrom } from "pg-copy-streams";
|
||||
import path from "path";
|
||||
import { branchTests } from "./branches.js";
|
||||
import { databaseTests } from "./databases.js";
|
||||
import { docsTests } from "./docs.js";
|
||||
import { logTests } from "./logs.js";
|
||||
import { assertEqualRows } from "../helpers.js";
|
||||
import { mergeTests } from "./merge.js";
|
||||
import { tableTests } from "./table.js";
|
||||
import { schemaTests } from "./schemas.js";
|
||||
import { tagsTests } from "./tags.js";
|
||||
import { viewsTests } from "./views.js";
|
||||
import { diffTests } from "./diffs.js";
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const testDataPath = args[3];
|
||||
|
||||
export default async function runWorkbenchTests(database) {
|
||||
await runTests(database, databaseTests, "database");
|
||||
await runTests(database, branchTests, "branches");
|
||||
await runTests(database, schemaTests, "schemas");
|
||||
await runTests(database, logTests, "logs");
|
||||
await runTests(database, mergeTests, "merge");
|
||||
await runTests(database, tableTests, "tables");
|
||||
await runTests(database, docsTests, "docs");
|
||||
await runTests(database, tagsTests, "tags");
|
||||
await runTests(database, viewsTests, "views");
|
||||
await runTests(database, diffTests, "diffs");
|
||||
}
|
||||
|
||||
async function runTests(database, tests, name) {
|
||||
console.log("Running tests for", name);
|
||||
await Promise.all(
|
||||
tests.map(async (test) => {
|
||||
if (test.skip) return;
|
||||
|
||||
if (test.file) {
|
||||
const filePath = path.resolve(testDataPath, test.file);
|
||||
try {
|
||||
// TODO: Is it possible to test the COPY FROM output?
|
||||
const ingestStream = database.client.query(copyFrom(test.q));
|
||||
const sourceStream = fs.createReadStream(filePath);
|
||||
await pipeline([sourceStream, ingestStream]);
|
||||
} catch (err) {
|
||||
console.log("Query errored:", test.q);
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return database
|
||||
.query(test.q, test.p)
|
||||
.then((data) => {
|
||||
assertEqualRows(test, data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (test.expectedErr) {
|
||||
if (err.message.includes(test.expectedErr)) {
|
||||
return;
|
||||
} else {
|
||||
console.log("Query error did not match expected:", test.q);
|
||||
}
|
||||
} else {
|
||||
console.log("Query errored:", test.q);
|
||||
}
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import { logsMatcher } from "./matchers.js";
|
||||
import { dbName } from "../helpers.js";
|
||||
|
||||
export const logTests = [
|
||||
{
|
||||
q: `SELECT * FROM DOLT_LOG('main', '--parents') LIMIT 10 OFFSET 0;`, // TODO: Prepared not working
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "postgres",
|
||||
email: "postgres@127.0.0.1",
|
||||
date: "",
|
||||
message: "CREATE DATABASE",
|
||||
parents: ["3orrg69ou1loj2ph21guie3r2lf8bsab"],
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
date: "",
|
||||
message: "Initialize data repository",
|
||||
parents: [],
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: logsMatcher,
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/mybranch';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.log;`, // TODO: If we decide to implement AS OF, use here instead of USE statement above and below
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt",
|
||||
email: "dolt@dolthub.com",
|
||||
date: "",
|
||||
message: "Create table test",
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "postgres",
|
||||
email: "postgres@127.0.0.1",
|
||||
date: "",
|
||||
message: "CREATE DATABASE",
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
date: "",
|
||||
message: "Initialize data repository",
|
||||
},
|
||||
],
|
||||
},
|
||||
matcher: logsMatcher,
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/main';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM DOLT_LOG('main..mybranch', '--parents')`, // TODO: Prepared not working
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt",
|
||||
email: "dolt@dolthub.com",
|
||||
date: "",
|
||||
message: "Create table test",
|
||||
parents: [""],
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: logsMatcher,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,173 @@
|
||||
function matcher(rows, exp, exceptionKeys, getExceptionIsValid) {
|
||||
// Row lengths match
|
||||
if (rows.length !== exp.length) {
|
||||
console.log("row lengths don't match", rows.length, exp.length);
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const rowKeys = Object.keys(rows[i]);
|
||||
const expKeys = Object.keys(exp[i]);
|
||||
// Row key lengths match
|
||||
if (rowKeys.length !== expKeys.length) {
|
||||
console.log(
|
||||
"row key lengths don't match",
|
||||
rowKeys.length,
|
||||
expKeys.length
|
||||
);
|
||||
return false;
|
||||
}
|
||||
// Row key values match
|
||||
for (let j = 0; j < rowKeys.length; j++) {
|
||||
const rowKey = rowKeys[j];
|
||||
// Check if key has an exception function
|
||||
if (exceptionKeys.includes(rowKey)) {
|
||||
const isValid = getExceptionIsValid(rows[i], rowKey, exp[i]);
|
||||
if (!isValid) {
|
||||
console.log("exception was not valid for key:", rowKey);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Compare cell values
|
||||
const cellVal = JSON.stringify(rows[i][rowKey]);
|
||||
const expCellVal = JSON.stringify(exp[i][rowKey]);
|
||||
if (cellVal !== expCellVal) {
|
||||
console.log("values don't match", cellVal, expCellVal);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function commitHashIsValid(commit) {
|
||||
return commit === "STAGED" || commit === "WORKING" || commit.length === 32;
|
||||
}
|
||||
|
||||
function dateIsValid(date) {
|
||||
return JSON.stringify(date).length > 0;
|
||||
}
|
||||
|
||||
export function branchesMatcher(data, exp) {
|
||||
const exceptionKeys = ["hash", "latest_commit_date"];
|
||||
|
||||
function getExceptionIsValid(row, key) {
|
||||
const val = row[key];
|
||||
switch (key) {
|
||||
case "hash":
|
||||
return commitHashIsValid(val);
|
||||
case "latest_commit_date":
|
||||
return dateIsValid(val);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher(data.rows, exp.rows, exceptionKeys, getExceptionIsValid);
|
||||
}
|
||||
|
||||
export function logsMatcher(data, exp) {
|
||||
const exceptionKeys = ["commit_hash", "date", "parents"];
|
||||
|
||||
function getExceptionIsValid(row, key, expRow) {
|
||||
const val = row[key];
|
||||
switch (key) {
|
||||
case "commit_hash":
|
||||
return commitHashIsValid(val);
|
||||
case "date":
|
||||
return dateIsValid(val);
|
||||
case "parents":
|
||||
const numParents = val.split(", ").filter((v) => !!v.length).length;
|
||||
const expParents = expRow.parents.length;
|
||||
return numParents === expParents;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher(data.rows, exp.rows, exceptionKeys, getExceptionIsValid);
|
||||
}
|
||||
|
||||
export function mergeBaseMatcher(data) {
|
||||
if (data.rows.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
return commitHashIsValid(data.rows[0].dolt_merge_base);
|
||||
}
|
||||
|
||||
export function mergeMatcher(data, exp) {
|
||||
if (data.rows.length !== 1) {
|
||||
console.log("Rows length not 1", data.rows.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
const row = data.rows[0].dolt_merge;
|
||||
const expRow = exp.rows[0].dolt_merge;
|
||||
|
||||
// Check valid commit hash
|
||||
if (!commitHashIsValid(row[0])) {
|
||||
console.log("Invalid commit hash", row[0]);
|
||||
return false;
|
||||
}
|
||||
// Check the rest of the fields
|
||||
for (let i = 1; i < row.length; i++) {
|
||||
if (row[i] !== expRow[i]) {
|
||||
console.log("Values don't match", row[i], expRow[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function tagsMatcher(data, exp) {
|
||||
const exceptionKeys = ["tag_hash", "date"];
|
||||
|
||||
function getExceptionIsValid(row, key) {
|
||||
const val = row[key];
|
||||
switch (key) {
|
||||
case "tag_hash":
|
||||
return commitHashIsValid(val);
|
||||
case "date":
|
||||
return dateIsValid(val);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher(data.rows, exp.rows, exceptionKeys, getExceptionIsValid);
|
||||
}
|
||||
|
||||
export function diffRowsMatcher(data, exp) {
|
||||
const exceptionKeys = ["to_commit_date", "from_commit_date"];
|
||||
|
||||
function getExceptionIsValid(row, key) {
|
||||
const val = row[key];
|
||||
switch (key) {
|
||||
case "to_commit_date":
|
||||
case "from_commit_date":
|
||||
return dateIsValid(val);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher(data.rows, exp.rows, exceptionKeys, getExceptionIsValid);
|
||||
}
|
||||
|
||||
export function patchRowsMatcher(data, exp) {
|
||||
const exceptionKeys = ["to_commit_hash", "from_commit_hash"];
|
||||
|
||||
function getExceptionIsValid(row, key) {
|
||||
const val = row[key];
|
||||
switch (key) {
|
||||
case "to_commit_hash":
|
||||
case "from_commit_hash":
|
||||
return commitHashIsValid(val);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return matcher(data.rows, exp.rows, exceptionKeys, getExceptionIsValid);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { doltStatusFields } from "../fields.js";
|
||||
import { logsMatcher, mergeBaseMatcher, mergeMatcher } from "./matchers.js";
|
||||
|
||||
export const mergeTests = [
|
||||
{
|
||||
q: `SELECT DOLT_MERGE_BASE($1::text, $2::text);`,
|
||||
p: ["mybranch", "main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_merge_base: "" }],
|
||||
fields: [],
|
||||
},
|
||||
matcher: mergeBaseMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_MERGE($1::text, '--no-ff', '-m', $2::text)`,
|
||||
p: ["mybranch", "Merge mybranch into main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
dolt_merge: ["", "0", "0", "merge successful"],
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: mergeMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM DOLT_LOG('main', '--parents') LIMIT 10 OFFSET 0;`, // TODO: Prepared not working
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
commit_hash: "",
|
||||
message: "Merge mybranch into main",
|
||||
committer: "postgres",
|
||||
email: "postgres@127.0.0.1",
|
||||
date: "",
|
||||
parents: ["", ""],
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt",
|
||||
email: "dolt@dolthub.com",
|
||||
date: "",
|
||||
message: "Create table test",
|
||||
parents: [""],
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "postgres",
|
||||
email: "postgres@127.0.0.1",
|
||||
date: "",
|
||||
message: "CREATE DATABASE",
|
||||
parents: [""],
|
||||
},
|
||||
{
|
||||
commit_hash: "",
|
||||
committer: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
date: "",
|
||||
message: "Initialize data repository",
|
||||
parents: [],
|
||||
},
|
||||
],
|
||||
fields: [],
|
||||
},
|
||||
matcher: logsMatcher,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,197 @@
|
||||
import {
|
||||
doltBranchFields,
|
||||
doltStatusFields,
|
||||
doltCommitFields,
|
||||
schemaNameField,
|
||||
pgTablesFields,
|
||||
} from "../fields.js";
|
||||
import { dbName } from "../helpers.js";
|
||||
|
||||
export const schemaTests = [
|
||||
{
|
||||
q: `SELECT DOLT_BRANCH($1::text, $2::text)`, // TODO: Should work without casts
|
||||
p: ["schemabranch", "main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_branch: ["0"] }],
|
||||
fields: doltBranchFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/schemabranch';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `create table testpub (pk int, "value" int, primary key(pk));`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-Am', $1::text, '--author', $2::text);`,
|
||||
p: ["Create table testpub", "Dolt <dolt@dolthub.com>"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `CREATE SCHEMA testschema;`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SET SEARCH_PATH = 'testschema';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `create table test2 (pk int, "value" int, primary key(pk));`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "testschema.test2",
|
||||
staged: false,
|
||||
status: "new table",
|
||||
},
|
||||
{ table_name: "testschema", staged: false, status: "new schema" },
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT schema_name FROM information_schema.schemata WHERE catalog_name = $1;`,
|
||||
p: [`${dbName}/schemabranch`],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 5,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ schema_name: "dolt" },
|
||||
{ schema_name: "pg_catalog" },
|
||||
{ schema_name: "public" },
|
||||
{ schema_name: "testschema" },
|
||||
{ schema_name: "information_schema" },
|
||||
],
|
||||
fields: [schemaNameField],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-Am', $1::text, '--author', $2::text);`,
|
||||
p: ["Create table test2", "Dolt <dolt@dolthub.com>"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: "" }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT schemaname, tablename FROM pg_catalog.pg_tables where schemaname=$1;`,
|
||||
p: ["testschema"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ schemaname: "testschema", tablename: "test2" }],
|
||||
fields: pgTablesFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SET SEARCH_PATH = 'public';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT schemaname, tablename FROM pg_catalog.pg_tables where schemaname=$1;`,
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ schemaname: "public", tablename: "testpub" }],
|
||||
fields: pgTablesFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/main';`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT schema_name FROM information_schema.schemata WHERE catalog_name = $1;`,
|
||||
p: [`${dbName}/main`],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ schema_name: "dolt" },
|
||||
{ schema_name: "pg_catalog" },
|
||||
{ schema_name: "public" },
|
||||
{ schema_name: "information_schema" },
|
||||
],
|
||||
fields: [schemaNameField],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT schemaname, tablename FROM pg_catalog.pg_tables where schemaname=$1;`,
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: pgTablesFields,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,455 @@
|
||||
import { dbName } from "../helpers.js";
|
||||
import {
|
||||
doltAddFields,
|
||||
doltCheckoutFields,
|
||||
doltCommitFields,
|
||||
doltDiffStatFields,
|
||||
doltResetFields,
|
||||
doltStatusFields,
|
||||
infoSchemaKeyColumnUsageFields,
|
||||
} from "../fields.js";
|
||||
|
||||
const testInfoFields = [
|
||||
{
|
||||
name: "id",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 23,
|
||||
dataTypeSize: 4,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "info",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 1020,
|
||||
dataTypeModifier: 259,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "test_pk",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 23,
|
||||
dataTypeSize: 4,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
];
|
||||
|
||||
export const tableTests = [
|
||||
{
|
||||
q: "SET search_path TO DEFAULT",
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "INSERT INTO test VALUES (0, 0), (1, 1), (2,2)",
|
||||
res: {
|
||||
command: "INSERT",
|
||||
rowCount: 3,
|
||||
oid: 0,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `CREATE UNIQUE INDEX test_idx ON test (pk, value)`,
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT ordinal_position, column_name, udt_name as data_type, is_nullable, column_default FROM information_schema.columns WHERE table_catalog=$1 AND table_schema = $2 AND table_name = $3;`,
|
||||
p: [`${dbName}/main`, "public", "test"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
ordinal_position: 1,
|
||||
column_name: "pk",
|
||||
data_type: "int4",
|
||||
is_nullable: "NO",
|
||||
column_default: null,
|
||||
},
|
||||
{
|
||||
ordinal_position: 2,
|
||||
column_name: "value",
|
||||
data_type: "int4",
|
||||
is_nullable: "YES",
|
||||
column_default: null,
|
||||
},
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
name: "ordinal_position",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 23,
|
||||
dataTypeSize: 4,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "column_name",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "data_type",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "is_nullable",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 12,
|
||||
dataTypeModifier: 7,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "column_default",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 25,
|
||||
dataTypeSize: -1,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Add some rows and a column index"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: [""] }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
skip: true, // TODO: ORDER BY is not yet supported
|
||||
q: `SELECT
|
||||
table_name, index_name, comment, non_unique, GROUP_CONCAT(column_name ORDER BY seq_in_index) AS COLUMNS
|
||||
FROM information_schema.statistics
|
||||
WHERE table_catalog=$1 AND table_schema=$2 AND table_name=$3 AND index_name!='PRIMARY'
|
||||
GROUP BY index_name;`,
|
||||
p: [`${dbName}/main`, "public", "test"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
TABLE_NAME: "test",
|
||||
INDEX_NAME: "test_idx",
|
||||
COMMENT: "",
|
||||
NON_UNIQUE: 0,
|
||||
COLUMNS: "pk,value",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "CREATE TABLE test_info (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references test(pk))",
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "INSERT INTO test_info VALUES (1, 'info about test pk 0', 0)",
|
||||
res: {
|
||||
command: "INSERT",
|
||||
rowCount: 1,
|
||||
oid: 0,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Add test_info with foreign key"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_commit: [""] }],
|
||||
fields: doltCommitFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT "table_schema", "table_name" FROM "information_schema"."tables" WHERE "table_schema" = $1 AND "table_catalog" = $2;`,
|
||||
p: ["public", `${dbName}/main`],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_schema: "public", table_name: "test" },
|
||||
{ table_schema: "public", table_name: "test_info" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
name: "table_schema",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "table_name",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name=$1 AND table_schema=$2 AND table_catalog=$3 AND referenced_table_schema IS NOT NULL`,
|
||||
p: ["test_info", "public", `${dbName}/main`],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
CONSTRAINT_CATALOG: `${dbName}/main`,
|
||||
CONSTRAINT_SCHEMA: "public",
|
||||
CONSTRAINT_NAME: "test_info_test_pk_fkey",
|
||||
TABLE_CATALOG: `${dbName}/main`,
|
||||
TABLE_SCHEMA: "public",
|
||||
TABLE_NAME: "test_info",
|
||||
COLUMN_NAME: "test_pk",
|
||||
ORDINAL_POSITION: 1,
|
||||
POSITION_IN_UNIQUE_CONSTRAINT: 1,
|
||||
REFERENCED_TABLE_SCHEMA: `${dbName}/main`,
|
||||
REFERENCED_TABLE_NAME: "test",
|
||||
REFERENCED_COLUMN_NAME: "pk",
|
||||
},
|
||||
],
|
||||
fields: infoSchemaKeyColumnUsageFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM "public"."test_info" "public.test_info" ORDER BY id ASC LIMIT 10;`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ id: 1, info: "info about test pk 0", test_pk: 0 }],
|
||||
fields: testInfoFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `USE '${dbName}/main'`,
|
||||
res: {
|
||||
command: "SET",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
|
||||
// Copy from tests
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `COPY "test_info" FROM STDIN WITH (FORMAT csv, HEADER TRUE);`,
|
||||
file: "insert_test_info.csv",
|
||||
res: { command: "COPY", rowCount: 3, oid: null, rows: [], fields: [] },
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM test_info",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 4,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ id: 1, info: "info about test pk 0", test_pk: 0 },
|
||||
{ id: 4, info: "string for 4", test_pk: 1 },
|
||||
{ id: 5, info: "string for 5", test_pk: 0 },
|
||||
{ id: 6, info: "string for 6", test_pk: 0 },
|
||||
],
|
||||
fields: testInfoFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING')", // TODO: Prepared not working
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: "1",
|
||||
rows_added: "3",
|
||||
rows_deleted: "0",
|
||||
rows_modified: "0",
|
||||
cells_added: "9",
|
||||
cells_deleted: "0",
|
||||
cells_modified: "0",
|
||||
old_row_count: "1",
|
||||
new_row_count: "4",
|
||||
old_cell_count: "3",
|
||||
new_cell_count: "12",
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `COPY "test_info" FROM STDIN WITH (FORMAT csv, HEADER TRUE, DELIMITER '|');`,
|
||||
file: "insert_test_info.psv",
|
||||
res: { command: "COPY", rowCount: 3, oid: null, rows: [], fields: [] },
|
||||
},
|
||||
{
|
||||
skip: true,
|
||||
q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
table_name: "public.test_info",
|
||||
rows_unmodified: 0,
|
||||
rows_added: 3,
|
||||
rows_deleted: 0,
|
||||
rows_modified: 1,
|
||||
cells_added: 9,
|
||||
cells_deleted: 0,
|
||||
cells_modified: 1,
|
||||
old_row_count: 1,
|
||||
new_row_count: 4,
|
||||
old_cell_count: 3,
|
||||
new_cell_count: 12,
|
||||
},
|
||||
],
|
||||
fields: doltDiffStatFields,
|
||||
},
|
||||
},
|
||||
|
||||
// Add and revert load data changes
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_name: "public.test_info", staged: false, status: "modified" },
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT DOLT_ADD('.')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_add: ["0"] }],
|
||||
fields: doltAddFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_name: "public.test_info", staged: true, status: "modified" },
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT DOLT_RESET('test_info');",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_reset: ["0"] }],
|
||||
fields: doltResetFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_name: "public.test_info", staged: false, status: "modified" },
|
||||
],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT DOLT_CHECKOUT('test_info')",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_checkout: ["0"] }],
|
||||
fields: doltCheckoutFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT * FROM dolt.status`,
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltStatusFields,
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,121 @@
|
||||
import { doltTagFields, doltTagsFields } from "../fields.js";
|
||||
import { tagsMatcher } from "./matchers.js";
|
||||
|
||||
export const tagsTests = [
|
||||
{
|
||||
q: "SELECT * FROM dolt.tags ORDER BY date DESC",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltTagsFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_TAG($1::text, $2::text);`,
|
||||
p: ["mytag", "main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_tag: ["0"] }],
|
||||
fields: doltTagFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt.tags ORDER BY date DESC",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
tag_name: "mytag",
|
||||
message: "",
|
||||
tagger: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
tag_hash: "",
|
||||
date: "",
|
||||
},
|
||||
],
|
||||
fields: doltTagsFields,
|
||||
},
|
||||
matcher: tagsMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_TAG('-m', $1::text, $2::text, $3::text)`,
|
||||
p: ["latest release", "mytagnew", "main"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_tag: ["0"] }],
|
||||
fields: doltTagFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt.tags ORDER BY date DESC",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
tag_name: "mytagnew",
|
||||
message: "latest release",
|
||||
tagger: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
tag_hash: "",
|
||||
date: "",
|
||||
},
|
||||
{
|
||||
tag_name: "mytag",
|
||||
message: "",
|
||||
tagger: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
tag_hash: "",
|
||||
date: "",
|
||||
},
|
||||
],
|
||||
fields: doltTagsFields,
|
||||
},
|
||||
matcher: tagsMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_TAG('-d', $1::text)`,
|
||||
p: ["mytagnew"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_tag: ["0"] }],
|
||||
fields: doltTagFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt.tags ORDER BY date DESC",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
tag_name: "mytag",
|
||||
message: "",
|
||||
tagger: "Dolt System Account",
|
||||
email: "doltuser@dolthub.com",
|
||||
tag_hash: "",
|
||||
date: "",
|
||||
},
|
||||
],
|
||||
fields: doltTagsFields,
|
||||
},
|
||||
matcher: tagsMatcher,
|
||||
},
|
||||
{
|
||||
q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`,
|
||||
p: ["Add a tag"],
|
||||
expectedErr: "nothing to commit",
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,196 @@
|
||||
import {
|
||||
doltCheckoutFields,
|
||||
doltSchemasFields,
|
||||
pgTablesFields,
|
||||
} from "../fields.js";
|
||||
|
||||
export const viewsTests = [
|
||||
{
|
||||
q: "SELECT DOLT_CHECKOUT('-b', $1::text);",
|
||||
p: ["more-updates"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ dolt_checkout: ["0", "Switched to branch 'more-updates'"] }],
|
||||
fields: doltCheckoutFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_schemas LIMIT 10 OFFSET 0;",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 0,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: doltSchemasFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "CREATE VIEW myview AS SELECT * FROM test;",
|
||||
res: {
|
||||
command: "CREATE",
|
||||
rowCount: null,
|
||||
oid: null,
|
||||
rows: [],
|
||||
fields: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: "SELECT * FROM dolt_schemas LIMIT 10 OFFSET 0",
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
type: "view",
|
||||
name: "myview",
|
||||
fragment: "CREATE VIEW myview AS SELECT * FROM test",
|
||||
extra: { CreatedAt: 0 },
|
||||
sql_mode:
|
||||
"NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES",
|
||||
},
|
||||
],
|
||||
fields: doltSchemasFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
// Excludes views
|
||||
q: "SELECT schemaname, tablename FROM pg_catalog.pg_tables where schemaname=$1;",
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 2,
|
||||
oid: null,
|
||||
rows: [
|
||||
{
|
||||
schemaname: "public",
|
||||
tablename: "test",
|
||||
},
|
||||
{
|
||||
schemaname: "public",
|
||||
tablename: "test_info",
|
||||
},
|
||||
],
|
||||
fields: pgTablesFields,
|
||||
},
|
||||
},
|
||||
{
|
||||
// Includes views
|
||||
q: "SELECT table_name FROM INFORMATION_SCHEMA.views WHERE table_schema = $1;",
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ table_name: "myview" }],
|
||||
fields: [
|
||||
{
|
||||
name: "table_name",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
// Includes views
|
||||
q: "SELECT viewname FROM pg_catalog.pg_views WHERE schemaname=$1;",
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ viewname: "myview" }],
|
||||
fields: [
|
||||
{
|
||||
name: "viewname",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 19,
|
||||
dataTypeSize: 64,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
// Includes tables and views
|
||||
q: "SELECT table_schema, table_name, table_type FROM INFORMATION_SCHEMA.tables WHERE table_schema = $1;",
|
||||
p: ["public"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 3,
|
||||
oid: null,
|
||||
rows: [
|
||||
{ table_schema: "public", table_name: "myview", table_type: "VIEW" },
|
||||
{
|
||||
table_schema: "public",
|
||||
table_name: "test",
|
||||
table_type: "BASE TABLE",
|
||||
},
|
||||
{
|
||||
table_schema: "public",
|
||||
table_name: "test_info",
|
||||
table_type: "BASE TABLE",
|
||||
},
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
name: "table_schema",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "table_name",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 1043,
|
||||
dataTypeSize: 256,
|
||||
dataTypeModifier: 68,
|
||||
format: "text",
|
||||
},
|
||||
{
|
||||
name: "table_type",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 25,
|
||||
dataTypeSize: -1,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
q: `SELECT pg_get_viewdef($1::regclass, true)`,
|
||||
p: ["myview"],
|
||||
res: {
|
||||
command: "SELECT",
|
||||
rowCount: 1,
|
||||
oid: null,
|
||||
rows: [{ pg_get_viewdef: "SELECT * FROM test" }],
|
||||
fields: [
|
||||
{
|
||||
name: "pg_get_viewdef",
|
||||
tableID: 0,
|
||||
columnID: 0,
|
||||
dataTypeID: 25,
|
||||
dataTypeSize: -1,
|
||||
dataTypeModifier: -1,
|
||||
format: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user