Skip to content

Commit 14be165

Browse files
Merge pull request #9678 from dolthub/nathan/doltUnitTesting
dolt_tests system table
2 parents 01775bc + 955775a commit 14be165

File tree

7 files changed

+429
-29
lines changed

7 files changed

+429
-29
lines changed

go/libraries/doltcore/doltdb/system_table.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ var getWriteableSystemTables = func() []string {
122122
IgnoreTableName,
123123
GetRebaseTableName(),
124124
GetQueryCatalogTableName(),
125+
GetTestsTableName(),
125126

126127
// TODO: find way to make these writable by the dolt process
127128
// TODO: but not by user
@@ -880,6 +881,10 @@ var GetStashesTableName = func() string {
880881

881882
var GetQueryCatalogTableName = func() string { return DoltQueryCatalogTableName }
882883

884+
var GetTestsTableName = func() string {
885+
return TestsTableName
886+
}
887+
883888
const (
884889
// LogTableName is the log system table name
885890
LogTableName = "dolt_log"
@@ -934,6 +939,9 @@ const (
934939

935940
// StashesTableName is the stashes system table name
936941
StashesTableName = "dolt_stashes"
942+
943+
// TestsTableName is the tests system table name
944+
TestsTableName = "dolt_tests"
937945
)
938946

939947
// DoltGeneratedTableNames is a list of all the generated dolt system tables that are not specific to a user table.

go/libraries/doltcore/sqle/database.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,17 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
828828
versionableTable := backingTable.(dtables.VersionableTable)
829829
dt, found = dtables.NewQueryCatalogTable(ctx, versionableTable), true
830830
}
831+
case doltdb.GetTestsTableName():
832+
backingTable, _, err := db.getTable(ctx, root, doltdb.GetTestsTableName())
833+
if err != nil {
834+
return nil, false, err
835+
}
836+
if backingTable == nil {
837+
dt, found = dtables.NewEmptyTestsTable(ctx), true
838+
} else {
839+
versionableTable := backingTable.(dtables.VersionableTable)
840+
dt, found = dtables.NewTestsTable(ctx, versionableTable), true
841+
}
831842
}
832843

833844
if found {

go/libraries/doltcore/sqle/dtables/query_catalog_table.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ type QueryCatalogTable struct {
3838
backingTable VersionableTable
3939
}
4040

41-
func (i *QueryCatalogTable) Name() string {
41+
func (qct *QueryCatalogTable) Name() string {
4242
return doltdb.DoltQueryCatalogTableName
4343
}
4444

45-
func (i *QueryCatalogTable) String() string {
45+
func (qct *QueryCatalogTable) String() string {
4646
return doltdb.DoltQueryCatalogTableName
4747
}
4848

@@ -58,28 +58,28 @@ func doltQueryCatalogSchema() sql.Schema {
5858

5959
var GetDoltQueryCatalogSchema = doltQueryCatalogSchema
6060

61-
func (i *QueryCatalogTable) Schema() sql.Schema {
61+
func (qct *QueryCatalogTable) Schema() sql.Schema {
6262
return GetDoltQueryCatalogSchema()
6363
}
6464

65-
func (i *QueryCatalogTable) Collation() sql.CollationID {
65+
func (qct *QueryCatalogTable) Collation() sql.CollationID {
6666
return sql.Collation_Default
6767
}
6868

69-
func (i *QueryCatalogTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
70-
if i.backingTable == nil {
69+
func (qct *QueryCatalogTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
70+
if qct.backingTable == nil {
7171
// no backing table; return an empty iter.
7272
return index.SinglePartitionIterFromNomsMap(nil), nil
7373
}
74-
return i.backingTable.Partitions(context)
74+
return qct.backingTable.Partitions(context)
7575
}
7676

77-
func (i *QueryCatalogTable) PartitionRows(context *sql.Context, partition sql.Partition) (sql.RowIter, error) {
78-
if i.backingTable == nil {
77+
func (qct *QueryCatalogTable) PartitionRows(context *sql.Context, partition sql.Partition) (sql.RowIter, error) {
78+
if qct.backingTable == nil {
7979
// no backing table; return an empty iter.
8080
return sql.RowsToRowIter(), nil
8181
}
82-
return i.backingTable.PartitionRows(context, partition)
82+
return qct.backingTable.PartitionRows(context, partition)
8383
}
8484

8585
// NewQueryCatalogTable creates a QueryCatalogTable
@@ -92,47 +92,47 @@ func NewEmptyQueryCatalogTable(_ *sql.Context) sql.Table {
9292
return &QueryCatalogTable{}
9393
}
9494

95-
func (qt *QueryCatalogTable) Replacer(_ *sql.Context) sql.RowReplacer {
96-
return newQueryCatalogWriter(qt)
95+
func (qct *QueryCatalogTable) Replacer(_ *sql.Context) sql.RowReplacer {
96+
return newQueryCatalogWriter(qct)
9797
}
9898

9999
// Updater returns a RowUpdater for this table. The RowUpdater will have Update called once for each row to be
100100
// updated, followed by a call to Close() when all rows have been processed.
101-
func (qt *QueryCatalogTable) Updater(_ *sql.Context) sql.RowUpdater {
102-
return newQueryCatalogWriter(qt)
101+
func (qct *QueryCatalogTable) Updater(_ *sql.Context) sql.RowUpdater {
102+
return newQueryCatalogWriter(qct)
103103
}
104104

105105
// Inserter returns an Inserter for this table. The Inserter will get one call to Insert() for each row to be
106106
// inserted, and will end with a call to Close() to finalize the insert operation.
107-
func (qt *QueryCatalogTable) Inserter(*sql.Context) sql.RowInserter {
108-
return newQueryCatalogWriter(qt)
107+
func (qct *QueryCatalogTable) Inserter(*sql.Context) sql.RowInserter {
108+
return newQueryCatalogWriter(qct)
109109
}
110110

111111
// Deleter returns a RowDeleter for this table. The RowDeleter will get one call to Delete for each row to be deleted,
112112
// and will end with a call to Close() to finalize the delete operation.
113-
func (qt *QueryCatalogTable) Deleter(*sql.Context) sql.RowDeleter {
114-
return newQueryCatalogWriter(qt)
113+
func (qct *QueryCatalogTable) Deleter(*sql.Context) sql.RowDeleter {
114+
return newQueryCatalogWriter(qct)
115115
}
116116

117-
func (qt *QueryCatalogTable) LockedToRoot(ctx *sql.Context, root doltdb.RootValue) (sql.IndexAddressableTable, error) {
118-
if qt.backingTable == nil {
119-
return qt, nil
117+
func (qct *QueryCatalogTable) LockedToRoot(ctx *sql.Context, root doltdb.RootValue) (sql.IndexAddressableTable, error) {
118+
if qct.backingTable == nil {
119+
return qct, nil
120120
}
121-
return qt.backingTable.LockedToRoot(ctx, root)
121+
return qct.backingTable.LockedToRoot(ctx, root)
122122
}
123123

124124
// IndexedAccess implements IndexAddressableTable, but QueryCatalogTable has no indexes.
125125
// Thus, this should never be called.
126-
func (qt *QueryCatalogTable) IndexedAccess(ctx *sql.Context, lookup sql.IndexLookup) sql.IndexedTable {
126+
func (qct *QueryCatalogTable) IndexedAccess(ctx *sql.Context, lookup sql.IndexLookup) sql.IndexedTable {
127127
panic("Unreachable")
128128
}
129129

130130
// GetIndexes implements IndexAddressableTable, but QueryCatalogTable has no indexes.
131-
func (qt *QueryCatalogTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
131+
func (qct *QueryCatalogTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
132132
return nil, nil
133133
}
134134

135-
func (qt *QueryCatalogTable) PreciseMatch() bool {
135+
func (qct *QueryCatalogTable) PreciseMatch() bool {
136136
return true
137137
}
138138

@@ -142,14 +142,14 @@ var _ sql.RowInserter = (*queryCatalogWriter)(nil)
142142
var _ sql.RowDeleter = (*queryCatalogWriter)(nil)
143143

144144
type queryCatalogWriter struct {
145-
qt *QueryCatalogTable
145+
qct *QueryCatalogTable
146146
errDuringStatementBegin error
147147
prevHash *hash.Hash
148148
tableWriter dsess.TableWriter
149149
}
150150

151-
func newQueryCatalogWriter(qt *QueryCatalogTable) *queryCatalogWriter {
152-
return &queryCatalogWriter{qt, nil, nil, nil}
151+
func newQueryCatalogWriter(qct *QueryCatalogTable) *queryCatalogWriter {
152+
return &queryCatalogWriter{qct, nil, nil, nil}
153153
}
154154

155155
// Insert inserts the row given, returning an error if it cannot. Insert will be called once for each row to process
@@ -184,7 +184,7 @@ func (qw *queryCatalogWriter) Delete(ctx *sql.Context, r sql.Row) error {
184184
// in some way that it may be returned to in the case of an error.
185185
func (qw *queryCatalogWriter) StatementBegin(ctx *sql.Context) {
186186
name := getDoltQueryCatalogTableName()
187-
prevHash, tableWriter, err := createWriteableSystemTable(ctx, name, qw.qt.Schema())
187+
prevHash, tableWriter, err := createWriteableSystemTable(ctx, name, qw.qct.Schema())
188188
if err != nil {
189189
qw.errDuringStatementBegin = err
190190
return

0 commit comments

Comments
 (0)