mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-27 03:09:14 -06:00
refactored doltcore/sqle testing for new format, switched to new format, many todos
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"go.uber.org/zap/buffer"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/test"
|
||||
@@ -105,7 +106,7 @@ func TestPushOnWriteHook(t *testing.T) {
|
||||
}
|
||||
|
||||
tSchema := createTestSchema(t)
|
||||
rowData, _ := createTestRowData(t, ddb.vrw, tSchema)
|
||||
rowData := createTestRowData(t, ddb.vrw, ddb.ns, tSchema)
|
||||
tbl, err := CreateTestTable(ddb.vrw, ddb.ns, tSchema, rowData)
|
||||
|
||||
if err != nil {
|
||||
@@ -243,8 +244,10 @@ func TestAsyncPushOnWrite(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
tSchema := createTestSchema(t)
|
||||
rowData, _ := createTestRowData(t, ddb.vrw, tSchema)
|
||||
rowData, err := durable.NewEmptyIndex(ctx, ddb.vrw, ddb.ns, tSchema)
|
||||
require.NoError(t, err)
|
||||
tbl, err := CreateTestTable(ddb.vrw, ddb.ns, tSchema, rowData)
|
||||
require.NoError(t, err)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create test table with data")
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb/durable"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
@@ -70,8 +71,8 @@ func createTestSchema(t *testing.T) schema.Schema {
|
||||
return sch
|
||||
}
|
||||
|
||||
func CreateTestTable(vrw types.ValueReadWriter, ns tree.NodeStore, tSchema schema.Schema, rowData types.Map) (*Table, error) {
|
||||
tbl, err := NewNomsTable(context.Background(), vrw, ns, tSchema, rowData, nil, nil)
|
||||
func CreateTestTable(vrw types.ValueReadWriter, ns tree.NodeStore, tSchema schema.Schema, rowData durable.Index) (*Table, error) {
|
||||
tbl, err := NewTable(context.Background(), vrw, ns, tSchema, rowData, nil, nil)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -80,20 +81,20 @@ func CreateTestTable(vrw types.ValueReadWriter, ns tree.NodeStore, tSchema schem
|
||||
return tbl, nil
|
||||
}
|
||||
|
||||
func createTestRowData(t *testing.T, vrw types.ValueReadWriter, sch schema.Schema) (types.Map, []row.Row) {
|
||||
return createTestRowDataFromTaggedValues(t, vrw, sch,
|
||||
row.TaggedValues{
|
||||
idTag: types.UUID(id0), firstTag: types.String("bill"), lastTag: types.String("billerson"), ageTag: types.Uint(53)},
|
||||
row.TaggedValues{
|
||||
idTag: types.UUID(id1), firstTag: types.String("eric"), lastTag: types.String("ericson"), isMarriedTag: types.Bool(true), ageTag: types.Uint(21)},
|
||||
row.TaggedValues{
|
||||
idTag: types.UUID(id2), firstTag: types.String("john"), lastTag: types.String("johnson"), isMarriedTag: types.Bool(false), ageTag: types.Uint(53)},
|
||||
row.TaggedValues{
|
||||
idTag: types.UUID(id3), firstTag: types.String("robert"), lastTag: types.String("robertson"), ageTag: types.Uint(36)},
|
||||
)
|
||||
}
|
||||
func createTestRowData(t *testing.T, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema) durable.Index {
|
||||
if types.Format_Default == types.Format_DOLT {
|
||||
idx, err := durable.NewEmptyIndex(context.Background(), vrw, ns, sch)
|
||||
require.NoError(t, err)
|
||||
return idx
|
||||
}
|
||||
|
||||
vals := []row.TaggedValues{
|
||||
{idTag: types.UUID(id0), firstTag: types.String("bill"), lastTag: types.String("billerson"), ageTag: types.Uint(53)},
|
||||
{idTag: types.UUID(id1), firstTag: types.String("eric"), lastTag: types.String("ericson"), isMarriedTag: types.Bool(true), ageTag: types.Uint(21)},
|
||||
{idTag: types.UUID(id2), firstTag: types.String("john"), lastTag: types.String("johnson"), isMarriedTag: types.Bool(false), ageTag: types.Uint(53)},
|
||||
{idTag: types.UUID(id3), firstTag: types.String("robert"), lastTag: types.String("robertson"), ageTag: types.Uint(36)},
|
||||
}
|
||||
|
||||
func createTestRowDataFromTaggedValues(t *testing.T, vrw types.ValueReadWriter, sch schema.Schema, vals ...row.TaggedValues) (types.Map, []row.Row) {
|
||||
var err error
|
||||
rows := make([]row.Row, len(vals))
|
||||
|
||||
@@ -110,8 +111,7 @@ func createTestRowDataFromTaggedValues(t *testing.T, vrw types.ValueReadWriter,
|
||||
|
||||
m, err = ed.Map(context.Background())
|
||||
assert.NoError(t, err)
|
||||
|
||||
return m, rows
|
||||
return durable.IndexFromNomsMap(m, vrw, ns)
|
||||
}
|
||||
|
||||
func TestIsValidTableName(t *testing.T) {
|
||||
@@ -290,8 +290,9 @@ func TestLDNoms(t *testing.T) {
|
||||
t.Fatal("There should be no tables in empty db")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tSchema := createTestSchema(t)
|
||||
rowData, _ := createTestRowData(t, ddb.vrw, tSchema)
|
||||
rowData, err := durable.NewEmptyIndex(ctx, ddb.vrw, ddb.ns, tSchema)
|
||||
tbl, err = CreateTestTable(ddb.vrw, ddb.ns, tSchema, rowData)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -98,6 +98,28 @@ var TimestampComparer = cmp.Comparer(func(x, y types.Timestamp) bool {
|
||||
return x.Equals(y)
|
||||
})
|
||||
|
||||
// CreateEmptyTestTable creates a new test table with the name, schema, and rows given.
|
||||
func CreateEmptyTestTable(t *testing.T, dEnv *env.DoltEnv, tableName string, sch schema.Schema) {
|
||||
ctx := context.Background()
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
vrw := dEnv.DoltDB.ValueReadWriter()
|
||||
ns := dEnv.DoltDB.NodeStore()
|
||||
|
||||
rows, err := durable.NewEmptyIndex(ctx, vrw, ns, sch)
|
||||
require.NoError(t, err)
|
||||
indexSet, err := durable.NewIndexSetWithEmptyIndexes(ctx, vrw, ns, sch)
|
||||
require.NoError(t, err)
|
||||
|
||||
tbl, err := doltdb.NewTable(ctx, vrw, ns, sch, rows, indexSet, nil)
|
||||
require.NoError(t, err)
|
||||
newRoot, err := root.PutTable(ctx, tableName, tbl)
|
||||
require.NoError(t, err)
|
||||
err = dEnv.UpdateWorkingRoot(ctx, newRoot)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// CreateTestTable creates a new test table with the name, schema, and rows given.
|
||||
func CreateTestTable(t *testing.T, dEnv *env.DoltEnv, tableName string, sch schema.Schema, rs ...row.Row) {
|
||||
imt := table.NewInMemTable(sch)
|
||||
|
||||
@@ -182,6 +182,9 @@ func assertSchemasEqual(t *testing.T, expected, actual sql.Schema) {
|
||||
// CreateTableFn returns a SetupFunc that creates a table with the rows given
|
||||
func CreateTableFn(tableName string, tableSchema schema.Schema, initialRows ...row.Row) SetupFn {
|
||||
return func(t *testing.T, dEnv *env.DoltEnv) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetest
|
||||
}
|
||||
dtestutils.CreateTestTable(t, dEnv, tableName, tableSchema, initialRows...)
|
||||
}
|
||||
}
|
||||
@@ -190,6 +193,9 @@ func CreateTableFn(tableName string, tableSchema schema.Schema, initialRows ...r
|
||||
// from Value types conforming to the schema given.
|
||||
func CreateTableWithRowsFn(tableName string, tableSchema schema.Schema, initialRows ...[]types.Value) SetupFn {
|
||||
return func(t *testing.T, dEnv *env.DoltEnv) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetest
|
||||
}
|
||||
rows := make([]row.Row, len(initialRows))
|
||||
for i, r := range initialRows {
|
||||
rows[i] = NewRowWithSchema(tableSchema, r...)
|
||||
|
||||
@@ -17,7 +17,6 @@ package index_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"testing"
|
||||
|
||||
sqle "github.com/dolthub/go-mysql-server"
|
||||
@@ -31,6 +30,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/index"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/typed/noms"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
// This tests mergeable indexes by using the SQL engine and intercepting specific calls. This way, we can verify that
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type jsonValueTest struct {
|
||||
@@ -43,6 +44,10 @@ type jsonValueTest struct {
|
||||
}
|
||||
|
||||
func TestJsonValues(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
|
||||
sqle.SkipByDefaultInCI(t)
|
||||
setupCommon := []testCommand{
|
||||
{cmd.SqlCmd{}, args{"-q", `create table js (pk int primary key, js json);`}},
|
||||
@@ -154,6 +159,10 @@ func testJsonValue(t *testing.T, test jsonValueTest, setupCommon []testCommand)
|
||||
|
||||
// round-trips large random JSON objects through the SQL engine
|
||||
func TestLargeJsonObjects(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
|
||||
sqle.SkipByDefaultInCI(t)
|
||||
setupCommon := []testCommand{
|
||||
{cmd.SqlCmd{}, args{"-q", `create table js (pk int primary key, js json);`}},
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
// This tests running queries against a modified subset of the stockmarket data set found here:
|
||||
@@ -20144,6 +20145,9 @@ func TestCreateTables(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInserts(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
sqle.SkipByDefaultInCI(t)
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
@@ -20170,6 +20174,9 @@ func TestInserts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInsertsWithIndexes(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
sqle.SkipByDefaultInCI(t)
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -33,6 +33,10 @@ import (
|
||||
)
|
||||
|
||||
func TestSqlBatchInserts(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
|
||||
insertStatements := []string{
|
||||
`insert into people (id, first_name, last_name, is_married, age, rating, uuid, num_episodes) values
|
||||
(7, "Maggie", "Simpson", false, 1, 5.1, '00000000-0000-0000-0000-000000000007', 677)`,
|
||||
@@ -58,11 +62,9 @@ func TestSqlBatchInserts(t *testing.T) {
|
||||
insertStatements[i], insertStatements[j] = insertStatements[j], insertStatements[i]
|
||||
})
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
|
||||
CreateTestDatabase(dEnv, t)
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
|
||||
tmpDir, err := dEnv.TempTableFilesDir()
|
||||
require.NoError(t, err)
|
||||
@@ -152,11 +154,10 @@ func TestSqlBatchInsertIgnoreReplace(t *testing.T) {
|
||||
(2, "Milhouse", "VanHouten", false, 1, 5.1, '00000000-0000-0000-0000-000000000008', 677)`,
|
||||
}
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
|
||||
CreateTestDatabase(dEnv, t)
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpDir, err := dEnv.TempTableFilesDir()
|
||||
require.NoError(t, err)
|
||||
@@ -196,11 +197,14 @@ func TestSqlBatchInsertIgnoreReplace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSqlBatchInsertErrors(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
ctx := context.Background()
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: convert to enginetests
|
||||
}
|
||||
|
||||
CreateTestDatabase(dEnv, t)
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
ctx := context.Background()
|
||||
dEnv := CreateTestDatabase(t)
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpDir, err := dEnv.TempTableFilesDir()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -255,13 +255,12 @@ func TestCreateTable(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
dtestutils.CreateTestTable(t, dEnv, PeopleTableName, PeopleTestSchema, AllPeopleRows...)
|
||||
ctx := context.Background()
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
dEnv := CreateEmptyTestDatabase(t)
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedRoot, err := ExecuteSql(t, dEnv, root, tt.query)
|
||||
|
||||
if tt.expectedErr == "" {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
@@ -329,10 +328,10 @@ func TestDropTable(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
ctx := context.Background()
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedRoot, err := ExecuteSql(t, dEnv, root, tt.query)
|
||||
|
||||
@@ -502,8 +501,7 @@ func TestAddColumn(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
ctx := context.Background()
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
|
||||
@@ -525,6 +523,10 @@ func TestAddColumn(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
equalSchemas(t, tt.expectedSchema, sch)
|
||||
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
return // todo: convert these to enginetests
|
||||
}
|
||||
|
||||
updatedTable, ok, err := updatedRoot.GetTable(ctx, "people")
|
||||
assert.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
@@ -617,8 +619,7 @@ func TestRenameColumn(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
ctx := context.Background()
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
|
||||
@@ -639,6 +640,10 @@ func TestRenameColumn(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedSchema, sch)
|
||||
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
return // todo: convert these to enginetests
|
||||
}
|
||||
|
||||
updatedTable, ok, err := updatedRoot.GetTable(ctx, "people")
|
||||
assert.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
@@ -727,8 +732,7 @@ func TestRenameTableStatements(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
dEnv := CreateTestDatabase(t)
|
||||
ctx := context.Background()
|
||||
root, _ := dEnv.WorkingRoot(ctx)
|
||||
|
||||
@@ -745,6 +749,7 @@ func TestRenameTableStatements(t *testing.T) {
|
||||
has, err := updatedRoot.HasTable(ctx, tt.oldTableName)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
|
||||
newTable, ok, err := updatedRoot.GetTable(ctx, tt.newTableName)
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
@@ -753,6 +758,10 @@ func TestRenameTableStatements(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.expectedSchema, sch)
|
||||
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
return // todo: convert these to enginetests
|
||||
}
|
||||
|
||||
rowData, err := newTable.GetNomsRowData(ctx)
|
||||
require.NoError(t, err)
|
||||
var foundRows []row.Row
|
||||
@@ -773,13 +782,17 @@ func TestRenameTableStatements(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAlterSystemTables(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("") // todo: convert to enginetests
|
||||
}
|
||||
systemTableNames := []string{"dolt_log", "dolt_history_people", "dolt_diff_people", "dolt_commit_diff_people"} // "dolt_docs",
|
||||
reservedTableNames := []string{"dolt_schemas", "dolt_query_catalog"}
|
||||
|
||||
var dEnv *env.DoltEnv
|
||||
setup := func() {
|
||||
dEnv = dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
dEnv = CreateTestDatabase(t)
|
||||
dtestutils.CreateEmptyTestTable(t, dEnv, "dolt_docs", doltdb.DocsSchema)
|
||||
dtestutils.CreateEmptyTestTable(t, dEnv, doltdb.SchemasTableName, SchemasTableSchema())
|
||||
|
||||
dtestutils.CreateTestTable(t, dEnv, "dolt_docs",
|
||||
doltdb.DocsSchema,
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -232,9 +231,7 @@ func testDeleteQuery(t *testing.T, test DeleteTest) {
|
||||
t.Skip("Skipping tests until " + singleDeleteQueryTest)
|
||||
}
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
|
||||
dEnv := CreateTestDatabase(t)
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -437,8 +436,7 @@ func testInsertQuery(t *testing.T, test InsertTest) {
|
||||
t.Skip("Skipping test broken on SQL engine")
|
||||
}
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateEmptyTestDatabase(dEnv, t)
|
||||
dEnv := CreateEmptyTestDatabase(t)
|
||||
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -95,8 +94,7 @@ func TestExecutePersist(t *testing.T) {
|
||||
// Tests the given query on a freshly created dataset, asserting that the result has the given schema and rows. If
|
||||
// expectedErr is set, asserts instead that the execution returns an error that matches.
|
||||
func testPersistQuery(t *testing.T, test PersistTest) {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateEmptyTestDatabase(dEnv, t)
|
||||
dEnv := CreateEmptyTestDatabase(t)
|
||||
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
@@ -304,8 +303,7 @@ func testReplaceQuery(t *testing.T, test ReplaceTest) {
|
||||
t.Skip("Skipping tests until " + singleReplaceQueryTest)
|
||||
}
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateEmptyTestDatabase(dEnv, t)
|
||||
dEnv := CreateEmptyTestDatabase(t)
|
||||
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
|
||||
@@ -85,10 +85,16 @@ func LoadedLocalLocation() *time.Location {
|
||||
|
||||
// BasicSelectTests cover basic select statement features and error handling
|
||||
func BasicSelectTests() []SelectTest {
|
||||
headCommitHash := "73hc2robs4v0kt9taoe3m5hd49dmrgun"
|
||||
if types.Format_Default == types.Format_DOLT_DEV {
|
||||
var headCommitHash string
|
||||
switch types.Format_Default {
|
||||
case types.Format_DOLT:
|
||||
headCommitHash = "4ej7hfduufg4o2837g3gc4p5uolrlmv9"
|
||||
case types.Format_DOLT_DEV:
|
||||
headCommitHash = "4ej7hfduufg4o2837g3gc4p5uolrlmv9"
|
||||
case types.Format_LD_1:
|
||||
headCommitHash = "73hc2robs4v0kt9taoe3m5hd49dmrgun"
|
||||
}
|
||||
|
||||
return []SelectTest{
|
||||
{
|
||||
Name: "select * on primary key",
|
||||
@@ -1452,6 +1458,9 @@ func TestSelect(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiffQueries(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("") // todo: convert to enginetests
|
||||
}
|
||||
for _, test := range SelectDiffTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
testSelectDiffQuery(t, test)
|
||||
@@ -1460,6 +1469,9 @@ func TestDiffQueries(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAsOfQueries(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("") // todo: convert to enginetests
|
||||
}
|
||||
for _, test := range AsOfTests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
// AS OF queries use the same history as the diff tests, so exercise the same test setup
|
||||
@@ -1582,9 +1594,7 @@ func testSelectQuery(t *testing.T, test SelectTest) {
|
||||
cleanup := installTestCommitClock()
|
||||
defer cleanup()
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
|
||||
dEnv := CreateTestDatabase(t)
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
}
|
||||
@@ -1627,6 +1637,10 @@ func testSelectQuery(t *testing.T, test SelectTest) {
|
||||
}
|
||||
|
||||
func testSelectDiffQuery(t *testing.T, test SelectTest) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("") // todo: convert to enginetests
|
||||
}
|
||||
|
||||
validateTest(t, test)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/json"
|
||||
@@ -419,9 +418,7 @@ func testUpdateQuery(t *testing.T, test UpdateTest) {
|
||||
t.Skip("Skipping tests until " + singleUpdateQueryTest)
|
||||
}
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
CreateTestDatabase(dEnv, t)
|
||||
|
||||
dEnv := CreateTestDatabase(t)
|
||||
if test.AdditionalSetup != nil {
|
||||
test.AdditionalSetup(t, dEnv)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ CREATE TABLE child (
|
||||
}
|
||||
|
||||
func TestTableEditorForeignKeyCascade(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
sqlStatement string
|
||||
@@ -178,6 +181,9 @@ ALTER TABLE three ADD FOREIGN KEY (v1, v2) REFERENCES two(v1, v2) ON DELETE CASC
|
||||
}
|
||||
|
||||
func TestTableEditorForeignKeySetNull(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
tests := []struct {
|
||||
sqlStatement string
|
||||
expectedOne []sql.Row
|
||||
@@ -228,6 +234,9 @@ ALTER TABLE two ADD FOREIGN KEY (v1) REFERENCES one(v1) ON DELETE SET NULL ON UP
|
||||
}
|
||||
|
||||
func TestTableEditorForeignKeyRestrict(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
for _, referenceOption := range []string{
|
||||
"ON DELETE RESTRICT ON UPDATE RESTRICT",
|
||||
"ON DELETE NO ACTION ON UPDATE NO ACTION",
|
||||
@@ -314,6 +323,9 @@ func TestTableEditorForeignKeyRestrict(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTableEditorForeignKeyViolations(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
tests := []struct {
|
||||
setup string
|
||||
trigger string
|
||||
@@ -378,6 +390,9 @@ ALTER TABLE three ADD FOREIGN KEY (v1, v2) REFERENCES two(v1, v2) ON DELETE CASC
|
||||
}
|
||||
|
||||
func TestTableEditorSelfReferentialForeignKeyRestrict(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
dEnv, initialRoot := setupEditorFkTest(t)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -448,6 +463,9 @@ func TestTableEditorSelfReferentialForeignKeyRestrict(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTableEditorSelfReferentialForeignKeyCascade(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
dEnv, initialRoot := setupEditorFkTest(t)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -548,6 +566,9 @@ func TestTableEditorSelfReferentialForeignKeyCascade(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTableEditorSelfReferentialForeignKeySetNull(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
dEnv, initialRoot := setupEditorFkTest(t)
|
||||
|
||||
ctx := context.Background()
|
||||
@@ -802,6 +823,9 @@ CREATE TABLE child (
|
||||
}
|
||||
|
||||
func TestTableEditorKeylessFKCascade(t *testing.T) {
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip() // todo: implement prolly row dump
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
sqlStatement string
|
||||
|
||||
@@ -145,6 +145,10 @@ UPDATE onepk SET pk1 = v1 + pk1 ORDER BY pk1 DESC;
|
||||
idx_v2v1 := twopkSch.Indexes().GetByName("idx_v2v1")
|
||||
require.NotNil(t, idx_v2v1)
|
||||
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("need a prolly sql row iter")
|
||||
}
|
||||
|
||||
idx_v1RowData, err := onepk.GetNomsIndexRowData(context.Background(), idx_v1.Name())
|
||||
require.NoError(t, err)
|
||||
idx_v2v1RowData, err := twopk.GetNomsIndexRowData(context.Background(), idx_v2v1.Name())
|
||||
@@ -310,6 +314,10 @@ UPDATE oneuni SET v1 = v1 + pk1;
|
||||
idx_v1v2 := twouniSch.Indexes().GetByName("idx_v1v2")
|
||||
require.NotNil(t, idx_v1v2)
|
||||
|
||||
if types.Format_Default != types.Format_LD_1 {
|
||||
t.Skip("need a prolly sql row iter")
|
||||
}
|
||||
|
||||
idx_v1RowData, err := oneuni.GetNomsIndexRowData(context.Background(), idx_v1.Name())
|
||||
require.NoError(t, err)
|
||||
idx_v1v2RowData, err := twouni.GetNomsIndexRowData(context.Background(), idx_v1v2.Name())
|
||||
|
||||
@@ -353,20 +353,6 @@ func GetAllRows(root *doltdb.RootValue, tableName string) ([]row.Row, error) {
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
// Creates a test database with the test data set in it
|
||||
func CreateTestDatabase(dEnv *env.DoltEnv, t *testing.T) {
|
||||
dtestutils.CreateTestTable(t, dEnv, PeopleTableName, PeopleTestSchema, AllPeopleRows...)
|
||||
dtestutils.CreateTestTable(t, dEnv, EpisodesTableName, EpisodesTestSchema, AllEpsRows...)
|
||||
dtestutils.CreateTestTable(t, dEnv, AppearancesTableName, AppearancesTestSchema, AllAppsRows...)
|
||||
}
|
||||
|
||||
// Creates a test database without any data in it
|
||||
func CreateEmptyTestDatabase(dEnv *env.DoltEnv, t *testing.T) {
|
||||
dtestutils.CreateTestTable(t, dEnv, PeopleTableName, PeopleTestSchema)
|
||||
dtestutils.CreateTestTable(t, dEnv, EpisodesTableName, EpisodesTestSchema)
|
||||
dtestutils.CreateTestTable(t, dEnv, AppearancesTableName, AppearancesTestSchema)
|
||||
}
|
||||
|
||||
var idColTag0TypeUUID = schema.NewColumn("id", 0, types.IntKind, true)
|
||||
var firstColTag1TypeStr = schema.NewColumn("first_name", 1, types.StringKind, false)
|
||||
var lastColTag2TypeStr = schema.NewColumn("last_name", 2, types.StringKind, false)
|
||||
|
||||
@@ -387,3 +387,51 @@ func CreateEnvWithSeedData(t *testing.T) *env.DoltEnv {
|
||||
require.NoError(t, err)
|
||||
return dEnv
|
||||
}
|
||||
|
||||
// CreateEmptyTestDatabase creates a test database without any data in it.
|
||||
func CreateEmptyTestDatabase(t *testing.T) *env.DoltEnv {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
dtestutils.CreateEmptyTestTable(t, dEnv, PeopleTableName, PeopleTestSchema)
|
||||
dtestutils.CreateEmptyTestTable(t, dEnv, EpisodesTableName, EpisodesTestSchema)
|
||||
dtestutils.CreateEmptyTestTable(t, dEnv, AppearancesTableName, AppearancesTestSchema)
|
||||
return dEnv
|
||||
}
|
||||
|
||||
// CreateTestDatabase creates a test database with the test data set in it.
|
||||
func CreateTestDatabase(t *testing.T) *env.DoltEnv {
|
||||
ctx := context.Background()
|
||||
dEnv := CreateEmptyTestDatabase(t)
|
||||
|
||||
const simpsonsRowData = `
|
||||
INSERT INTO people VALUES
|
||||
(0, "Homer", "Simpson", 1, 40, 8.5, NULL, NULL),
|
||||
(1, "Marge", "Simpson", 1, 38, 8, "00000000-0000-0000-0000-000000000001", 111),
|
||||
(2, "Bart", "Simpson", 0, 10, 9, "00000000-0000-0000-0000-000000000002", 222),
|
||||
(3, "Lisa", "Simpson", 0, 8, 10, "00000000-0000-0000-0000-000000000003", 333),
|
||||
(4, "Moe", "Szyslak", 0, 48, 6.5, "00000000-0000-0000-0000-000000000004", 444),
|
||||
(5, "Barney", "Gumble", 0, 40, 4, "00000000-0000-0000-0000-000000000005", 555);
|
||||
INSERT INTO episodes VALUES
|
||||
(1, "Simpsons Roasting On an Open Fire", "1989-12-18 03:00:00", 8.0),
|
||||
(2, "Bart the Genius", "1990-01-15 03:00:00", 9.0),
|
||||
(3, "Homer's Odyssey", "1990-01-22 03:00:00", 7.0),
|
||||
(4, "There's No Disgrace Like Home", "1990-01-29 03:00:00", 8.5);
|
||||
INSERT INTO appearances VALUES
|
||||
(0, 1, "Homer is great in this one"),
|
||||
(1, 1, "Marge is here too"),
|
||||
(0, 2, "Homer is great in this one too"),
|
||||
(2, 2, "This episode is named after Bart"),
|
||||
(3, 2, "Lisa is here too"),
|
||||
(4, 2, "I think there's a prank call scene"),
|
||||
(0, 3, "Homer is in every episode"),
|
||||
(1, 3, "Marge shows up a lot too"),
|
||||
(3, 3, "Lisa is the best Simpson"),
|
||||
(5, 3, "I'm making this all up");`
|
||||
|
||||
root, err := dEnv.WorkingRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
root, err = ExecuteSql(t, dEnv, root, simpsonsRowData)
|
||||
require.NoError(t, err)
|
||||
err = dEnv.UpdateWorkingRoot(ctx, root)
|
||||
require.NoError(t, err)
|
||||
return dEnv
|
||||
}
|
||||
|
||||
@@ -16,14 +16,12 @@ package writer_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/row"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
@@ -32,6 +30,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/sqlutil"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/writer"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/table/editor"
|
||||
"github.com/dolthub/dolt/go/store/types"
|
||||
)
|
||||
|
||||
type tableEditorTest struct {
|
||||
@@ -162,9 +161,7 @@ func TestTableEditor(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
expectedErr = nil
|
||||
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
sqle.CreateTestDatabase(dEnv, t)
|
||||
|
||||
dEnv := sqle.CreateTestDatabase(t)
|
||||
ctx := sqle.NewTestSQLCtx(context.Background())
|
||||
root, _ := dEnv.WorkingRoot(context.Background())
|
||||
tmpDir, err := dEnv.TempTableFilesDir()
|
||||
|
||||
@@ -50,4 +50,4 @@ const FormatDoltString = "__DOLT__"
|
||||
// data maps.
|
||||
const FormatDoltDevString = "__DOLT_DEV__"
|
||||
|
||||
var FormatDefaultString = FormatLD1String
|
||||
var FormatDefaultString = FormatDoltString
|
||||
|
||||
Reference in New Issue
Block a user