Skip to content

Commit

Permalink
Workbench tests for log, merge, table details (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 authored Sep 24, 2024
1 parent e5f884a commit fa58c0e
Show file tree
Hide file tree
Showing 14 changed files with 957 additions and 76 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
github.com/cockroachdb/errors v1.7.5
github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04
github.com/dolthub/dolt/go v0.40.5-0.20240924203939-2f79023217f7
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04 h1:snHOMQJOieEXdAOOM8icGhwp4p5IPLYPKyVKYZiPkQc=
github.com/dolthub/dolt/go v0.40.5-0.20240923204958-bf8d3e8f4d04/go.mod h1:1HBB+xUaDISZ6GrUmiiD//Ij5wExAAV1nPDpU4xPrmg=
github.com/dolthub/dolt/go v0.40.5-0.20240924203939-2f79023217f7 h1:Tgw1FOKBmOd0C+jZ/8nJuTwCdc5Sac8rlZLu6K0Pz70=
github.com/dolthub/dolt/go v0.40.5-0.20240924203939-2f79023217f7/go.mod h1:1HBB+xUaDISZ6GrUmiiD//Ij5wExAAV1nPDpU4xPrmg=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d h1:RZkQeYOrDrOWzCxaP2ttkvg4E2TM9n8lnEsIBLKjqkM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
Expand Down
139 changes: 139 additions & 0 deletions testing/go/dolt_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,144 @@ func TestDoltFunctions(t *testing.T) {
},
},
},
{
Name: "smoke test select dolt_merge",
SetUpScript: []string{
"CREATE TABLE t1 (pk int primary key);",
"SELECT DOLT_COMMIT('-Am', 'new table');",
"SELECT DOLT_CHECKOUT('-b', 'new-branch');",
"CREATE TABLE t2 (pk int primary key);",
"SELECT DOLT_COMMIT('-Am', 'new table on new branch');",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT DOLT_MERGE_BASE('main', 'new-branch');",
SkipResultsCheck: true,
},
{
Query: "SELECT DOLT_CHECKOUT('main');",
Expected: []sql.Row{
{"{0,\"Switched to branch 'main'\"}"},
},
},
{
Query: "select count(*) from dolt_log",
Expected: []sql.Row{
{3}, // initial commit, CREATE DATABASE commit, CREATE TABLE commit
},
},
{
Query: "SELECT DOLT_MERGE('new-branch', '--no-ff', '-m', 'merge new-branch into main');",
SkipResultsCheck: true,
},
{
Query: "select count(*) from dolt_log",
Expected: []sql.Row{
{5}, // initial commit, CREATE DATABASE commit, CREATE TABLE t1 commit, new CREATE TABLE t2 commit, merge commit
},
},
},
},
{
Name: "smoke test select dolt_reset",
SetUpScript: []string{
"CREATE TABLE t1 (pk int primary key);",
"INSERT INTO t1 VALUES (1);",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 0, "new table"},
},
},
{
Query: "SELECT DOLT_ADD('t1');",
Expected: []sql.Row{{"{0}"}},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 1, "new table"},
},
},
{
Query: "SELECT DOLT_RESET('t1');",
Expected: []sql.Row{{"{0}"}},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 0, "new table"},
},
},
},
},
{
Name: "smoke test select dolt_clean",
SetUpScript: []string{
"CREATE TABLE t1 (pk int primary key);",
"INSERT INTO t1 VALUES (1);",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 0, "new table"},
},
},
{
Query: "SELECT DOLT_CLEAN('t1');",
Expected: []sql.Row{{"{0}"}},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
{
Query: "CREATE TABLE t1 (pk int primary key);",
Expected: []sql.Row{},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 0, "new table"},
},
},
{
Skip: true, // TODO: function dolt_clean() does not exist
Query: "SELECT DOLT_CLEAN();",
Expected: []sql.Row{{"{0}"}},
},
{
Skip: true,
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
},
},
{
Name: "smoke test select dolt_checkout(table)",
SetUpScript: []string{
"CREATE TABLE t1 (pk int primary key);",
"INSERT INTO t1 VALUES (1);",
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t1", 0, "new table"},
},
},
{
Query: "SELECT DOLT_CHECKOUT('t1');",
Expected: []sql.Row{{"{0}"}},
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{},
},
},
},
})
}
135 changes: 135 additions & 0 deletions testing/postgres-client-tests/node/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ export const doltAddFields = [
},
];

export const doltResetFields = [
{
name: "dolt_reset",
tableID: 0,
columnID: 0,
dataTypeID: 1009,
dataTypeSize: -1,
dataTypeModifier: -1,
format: "text",
},
];

export const doltBranchFields = [
{
name: "dolt_branch",
Expand All @@ -46,6 +58,18 @@ export const doltCheckoutFields = [
},
];

export const doltCleanFields = [
{
name: "dolt_clean",
tableID: 0,
columnID: 0,
dataTypeID: 1009,
dataTypeSize: -1,
dataTypeModifier: -1,
format: "text",
},
];

export const doltCommitFields = [
{
name: "dolt_commit",
Expand Down Expand Up @@ -87,3 +111,114 @@ export const doltStatusFields = [
format: "text",
},
];

export const infoSchemaKeyColumnUsageFields = [
{
name: "CONSTRAINT_CATALOG",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "CONSTRAINT_SCHEMA",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "CONSTRAINT_NAME",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "TABLE_CATALOG",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "TABLE_SCHEMA",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "TABLE_NAME",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "COLUMN_NAME",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "ORDINAL_POSITION",
tableID: 0,
columnID: 0,
dataTypeID: 26,
dataTypeSize: 10,
dataTypeModifier: -1,
format: "text",
},
{
name: "POSITION_IN_UNIQUE_CONSTRAINT",
tableID: 0,
columnID: 0,
dataTypeID: 26,
dataTypeSize: 10,
dataTypeModifier: -1,
format: "text",
},
{
name: "REFERENCED_TABLE_SCHEMA",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "REFERENCED_TABLE_NAME",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
{
name: "REFERENCED_COLUMN_NAME",
tableID: 0,
columnID: 0,
dataTypeID: 1043,
dataTypeSize: 192,
dataTypeModifier: -1,
format: "text",
},
];
31 changes: 19 additions & 12 deletions testing/postgres-client-tests/node/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,32 @@ export function getConfig() {
};
}

export function assertEqualRows(test, data) {
const expected = test.res;
const resultStr = JSON.stringify(data);
const result = JSON.parse(resultStr);
if (!assertQueryResult(test.q, expected, data, test.matcher)) {
console.log("Query:", test.q);
console.log("Results:", result);
console.log("Expected:", expected);
throw new Error("Query failed");
} else {
console.log("Query succeeded:", test.q);
}
}

export function assertQueryResult(q, expected, data, matcher) {
if (matcher) {
return matcher(data, expected);
}
if (q.toLowerCase().includes("dolt_commit")) {
if (data.rows.length !== 1) return false;
const hash = data.rows[0].dolt_commit[0];
// dolt_commit row returns 32 character hash
return hash.length === 32;
}
if (q.toLowerCase().includes("dolt_merge")) {
if (data.rows.length !== 1) return false;
const [hash, fastForward, conflicts, message] = data.rows[0].dolt_merge;
return (
hash.length === 32 &&
expected.fastForward === fastForward &&
expected.conflicts === conflicts &&
expected.message === message
);
if (hash.length !== 32) {
console.log("Invalid hash for dolt_commit:", hash);
return false;
}
expected.rows[0].dolt_commit = data.rows[0].dolt_commit;
}

// Does partial matching of actual and expected results.
Expand Down
Loading

0 comments on commit fa58c0e

Please sign in to comment.