mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-26 19:46:39 -05:00
Merge pull request #729 from liquidata-inc/zachmu/engine-test
Run the go-mysql-server engine tests on dolt
This commit is contained in:
@@ -44,7 +44,7 @@ require (
|
||||
github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6
|
||||
github.com/kr/pretty v0.2.0 // indirect
|
||||
github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20200320155049-a8e482faeffd
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200527000206-1c2bbce60ff6
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200605170723-cd4f84b39578
|
||||
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0
|
||||
github.com/liquidata-inc/mmap-go v1.0.3
|
||||
github.com/liquidata-inc/sqllogictest/go v0.0.0-20200320151923-b11801f10e15
|
||||
@@ -91,6 +91,4 @@ replace github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi => ./
|
||||
|
||||
replace vitess.io/vitess => github.com/liquidata-inc/vitess v0.0.0-20200430040751-192bb76ecd8b
|
||||
|
||||
// replace github.com/liquidata-inc/go-mysql-server => ../../go-mysql-server
|
||||
|
||||
go 1.13
|
||||
|
||||
@@ -392,8 +392,8 @@ github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200527000206-1c2bbce60ff6 h1:Bd//sSg4AZlz+PO1dvtSNwsNB8aTxfLJcCnvjOSMrck=
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200527000206-1c2bbce60ff6/go.mod h1:Qo0l83LdX5Z77p0tTLyJTrttZywFm0S+RYo6Shi97tw=
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200605170723-cd4f84b39578 h1:fDv4huMp1Ubh/qVkkStpKxE1LgEIaLLQIkN5NUwAMBE=
|
||||
github.com/liquidata-inc/go-mysql-server v0.5.1-0.20200605170723-cd4f84b39578/go.mod h1:Qo0l83LdX5Z77p0tTLyJTrttZywFm0S+RYo6Shi97tw=
|
||||
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0 h1:phMgajKClMUiIr+hF2LGt8KRuUa2Vd2GI1sNgHgSXoU=
|
||||
github.com/liquidata-inc/ishell v0.0.0-20190514193646-693241f1f2a0/go.mod h1:YC1rI9k5gx8D02ljlbxDfZe80s/iq8bGvaaQsvR+qxs=
|
||||
github.com/liquidata-inc/mmap-go v1.0.3 h1:2LndAeAtup9rpvUmu4wZSYCsjCQ0Zpc+NqE+6+PnT7g=
|
||||
|
||||
@@ -251,7 +251,7 @@ func (bWr branchWriter) Delete(ctx *sql.Context, r sql.Row) error {
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return sql.ErrDeleteRowNotFound
|
||||
return sql.ErrDeleteRowNotFound.New()
|
||||
}
|
||||
|
||||
return bWr.bt.ddb.DeleteBranch(ctx, brRef)
|
||||
|
||||
@@ -644,6 +644,10 @@ func (db Database) RenameTable(ctx *sql.Context, oldName, newName string) error
|
||||
return ErrInvalidTableName.New(newName)
|
||||
}
|
||||
|
||||
if _, ok, _ := db.GetTableInsensitive(ctx, newName); ok {
|
||||
return sql.ErrTableAlreadyExists.New(newName)
|
||||
}
|
||||
|
||||
newRoot, err := alterschema.RenameTable(ctx, root, oldName, newName)
|
||||
|
||||
if err != nil {
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
// Copyright 2020 Liquidata, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package enginetest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/liquidata-inc/go-mysql-server/enginetest"
|
||||
)
|
||||
|
||||
func TestQueries(t *testing.T) {
|
||||
enginetest.TestQueries(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestVersionedQueries(t *testing.T) {
|
||||
enginetest.TestVersionedQueries(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
// Tests of choosing the correct execution plan independent of result correctness. Mostly useful for confirming that
|
||||
// the right indexes are being used for joining tables.
|
||||
func TestQueryPlans(t *testing.T) {
|
||||
t.Skipf("Skipping query plan tests until we have unified printing for query plans")
|
||||
enginetest.TestQueryPlans(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestQueryErrors(t *testing.T) {
|
||||
enginetest.TestQueryErrors(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestInfoSchema(t *testing.T) {
|
||||
enginetest.TestInfoSchema(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestColumnAliases(t *testing.T) {
|
||||
enginetest.TestColumnAliases(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestOrderByGroupBy(t *testing.T) {
|
||||
enginetest.TestOrderByGroupBy(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestAmbiguousColumnResolution(t *testing.T) {
|
||||
enginetest.TestAmbiguousColumnResolution(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestInsertInto(t *testing.T) {
|
||||
enginetest.TestInsertInto(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestInsertIntoErrors(t *testing.T) {
|
||||
enginetest.TestInsertIntoErrors(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestReplaceInto(t *testing.T) {
|
||||
t.Skipf("Skipping, replace returns the wrong number of rows in some cases")
|
||||
enginetest.TestReplaceInto(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestReplaceIntoErrors(t *testing.T) {
|
||||
enginetest.TestReplaceIntoErrors(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
enginetest.TestUpdate(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestUpdateErrors(t *testing.T) {
|
||||
enginetest.TestUpdateErrors(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestDeleteFrom(t *testing.T) {
|
||||
enginetest.TestDelete(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestDeleteFromErrors(t *testing.T) {
|
||||
enginetest.TestDeleteErrors(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestCreateTable(t *testing.T) {
|
||||
t.Skipf("Skipping: no support for BLOB type")
|
||||
enginetest.TestCreateTable(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestDropTable(t *testing.T) {
|
||||
enginetest.TestDropTable(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestRenameTable(t *testing.T) {
|
||||
enginetest.TestRenameTable(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestRenameColumn(t *testing.T) {
|
||||
t.Skipf("DDL tests break because of column comments")
|
||||
enginetest.TestRenameColumn(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestAddColumn(t *testing.T) {
|
||||
t.Skipf("DDL tests break because of column comments")
|
||||
enginetest.TestAddColumn(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestModifyColumn(t *testing.T) {
|
||||
t.Skip("Type changes aren't supported")
|
||||
enginetest.TestModifyColumn(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestDropColumn(t *testing.T) {
|
||||
t.Skipf("DDL tests break because of column comments")
|
||||
enginetest.TestDropColumn(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestExplode(t *testing.T) {
|
||||
t.Skipf("Unsupported types")
|
||||
enginetest.TestExplode(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestReadOnly(t *testing.T) {
|
||||
enginetest.TestReadOnly(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestViews(t *testing.T) {
|
||||
enginetest.TestViews(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestVersionedViews(t *testing.T) {
|
||||
enginetest.TestVersionedViews(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestNaturalJoin(t *testing.T) {
|
||||
enginetest.TestNaturalJoin(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestNaturalJoinEqual(t *testing.T) {
|
||||
enginetest.TestNaturalJoinEqual(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestNaturalJoinDisjoint(t *testing.T) {
|
||||
enginetest.TestNaturalJoinDisjoint(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
func TestInnerNestedInNaturalJoins(t *testing.T) {
|
||||
t.Skip("No primary key in test tables")
|
||||
enginetest.TestInnerNestedInNaturalJoins(t, newDoltHarness(t))
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// Copyright 2020 Liquidata, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package enginetest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/liquidata-inc/go-mysql-server/enginetest"
|
||||
"github.com/liquidata-inc/go-mysql-server/sql"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/dtestutils"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle"
|
||||
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle/dfunctions"
|
||||
)
|
||||
|
||||
type doltHarness struct {
|
||||
t *testing.T
|
||||
session *sqle.DoltSession
|
||||
mrEnv env.MultiRepoEnv
|
||||
}
|
||||
|
||||
var _ enginetest.Harness = (*doltHarness)(nil)
|
||||
var _ enginetest.SkippingHarness = (*doltHarness)(nil)
|
||||
var _ enginetest.IndexHarness = (*doltHarness)(nil)
|
||||
var _ enginetest.VersionedDBHarness = (*doltHarness)(nil)
|
||||
|
||||
func newDoltHarness(t *testing.T) *doltHarness {
|
||||
session, err := sqle.NewDoltSession(context.Background(), enginetest.NewBaseSession(), "test", "email@test.com")
|
||||
require.NoError(t, err)
|
||||
return &doltHarness{
|
||||
t: t,
|
||||
session: session,
|
||||
mrEnv: make(env.MultiRepoEnv),
|
||||
}
|
||||
}
|
||||
|
||||
// Logic to skip unsupported queries
|
||||
func (d *doltHarness) SkipQueryTest(query string) bool {
|
||||
lowerQuery := strings.ToLower(query)
|
||||
return strings.Contains(lowerQuery, "typestable") || // we don't support all the required types
|
||||
strings.Contains(lowerQuery, "show full columns") || // we set extra comment info
|
||||
lowerQuery == "show variables" || // we set extra variables
|
||||
strings.Contains(lowerQuery, "show create table") // we set extra comment info
|
||||
}
|
||||
|
||||
func (d *doltHarness) Parallelism() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (d *doltHarness) NewContext() *sql.Context {
|
||||
return sql.NewContext(
|
||||
context.Background(),
|
||||
sql.WithSession(d.session),
|
||||
sql.WithViewRegistry(sql.NewViewRegistry()),
|
||||
)
|
||||
}
|
||||
|
||||
func (d *doltHarness) SupportsNativeIndexCreation() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *doltHarness) NewDatabase(name string) sql.Database {
|
||||
dEnv := dtestutils.CreateTestEnv()
|
||||
root, err := dEnv.WorkingRoot(enginetest.NewContext(d))
|
||||
require.NoError(d.t, err)
|
||||
|
||||
d.mrEnv.AddEnv(name, dEnv)
|
||||
db := sqle.NewDatabase(name, dEnv.DoltDB, dEnv.RepoState, dEnv.RepoStateWriter())
|
||||
require.NoError(d.t, d.session.AddDB(enginetest.NewContext(d), db))
|
||||
require.NoError(d.t, db.SetRoot(enginetest.NewContext(d).WithCurrentDB(db.Name()), root))
|
||||
return db
|
||||
}
|
||||
|
||||
func (d *doltHarness) NewTable(db sql.Database, name string, schema sql.Schema) (sql.Table, error) {
|
||||
doltDatabase := db.(sqle.Database)
|
||||
err := doltDatabase.CreateTable(enginetest.NewContext(d).WithCurrentDB(db.Name()), name, schema)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
table, ok, err := doltDatabase.GetTableInsensitive(enginetest.NewContext(d).WithCurrentDB(db.Name()), name)
|
||||
|
||||
require.NoError(d.t, err)
|
||||
require.True(d.t, ok, "table %s not found after creation", name)
|
||||
return table, nil
|
||||
}
|
||||
|
||||
// Dolt doesn't version tables per se, just the entire database. So ignore the name and schema and just create a new
|
||||
// branch with the given name.
|
||||
func (d *doltHarness) NewTableAsOf(db sql.VersionedDatabase, name string, schema sql.Schema, asOf interface{}) sql.Table {
|
||||
table, err := d.NewTable(db, name, schema)
|
||||
if err != nil {
|
||||
require.True(d.t, sql.ErrTableAlreadyExists.Is(err))
|
||||
}
|
||||
|
||||
table, ok, err := db.GetTableInsensitive(enginetest.NewContext(d), name)
|
||||
require.NoError(d.t, err)
|
||||
require.True(d.t, ok)
|
||||
|
||||
return table
|
||||
}
|
||||
|
||||
// Dolt doesn't version tables per se, just the entire database. So ignore the name and schema and just create a new
|
||||
// branch with the given name.
|
||||
func (d *doltHarness) SnapshotTable(db sql.VersionedDatabase, name string, asOf interface{}) error {
|
||||
ddb := db.(sqle.Database)
|
||||
e := enginetest.NewEngineWithDbs(d.t, d.Parallelism(), []sql.Database{db}, nil)
|
||||
|
||||
if _, err := e.Catalog.FunctionRegistry.Function(dfunctions.CommitFuncName); sql.ErrFunctionNotFound.Is(err) {
|
||||
require.NoError(d.t,
|
||||
e.Catalog.FunctionRegistry.Register(sql.Function1{Name: dfunctions.CommitFuncName, Fn: dfunctions.NewCommitFunc}))
|
||||
}
|
||||
|
||||
asOfString, ok := asOf.(string)
|
||||
require.True(d.t, ok)
|
||||
|
||||
_, iter, err := e.Query(enginetest.NewContext(d),
|
||||
"set @@"+ddb.HeadKey()+" = COMMIT('test commit');")
|
||||
require.NoError(d.t, err)
|
||||
_, err = sql.RowIterToRows(iter)
|
||||
require.NoError(d.t, err)
|
||||
|
||||
_, iter, err = e.Query(enginetest.NewContext(d),
|
||||
"insert into dolt_branches (name, hash) values ('"+asOfString+"', @@"+ddb.HeadKey()+")")
|
||||
require.NoError(d.t, err)
|
||||
_, err = sql.RowIterToRows(iter)
|
||||
require.NoError(d.t, err)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -936,7 +936,7 @@ func TestRenameTable(t *testing.T) {
|
||||
{
|
||||
name: "table name in use",
|
||||
query: "rename table people to appearances",
|
||||
expectedErr: "table already exists",
|
||||
expectedErr: "already exists",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user