Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/dtables/tests_table.go (Go)

Code before:
var _ sql.Table = (*TestsTable)(nil)
var _ sql.UpdatableTable = (*TestsTable)(nil)
var _ sql.DeletableTable = (*TestsTable)(nil)
var _ sql.InsertableTable = (*TestsTable)(nil)
var _ sql.ReplaceableTable = (*TestsTable)(nil)
var _ sql.IndexAddressableTable = (*TestsTable)(nil)

// TestsTable is the system table that stores test definitions.
type TestsTable struct {
	backingTable VersionableTable
}

func (tt *TestsTable) Name() string {
	return doltdb.TestsTableName
}

func (tt *TestsTable) String() string {
	return doltdb.TestsTableName
}

func doltTestsSchema() sql.Schema {
	return []*sql.Column{
		{Name: "test_group", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_name", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_query", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "test_assertion", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
	}
}

// GetDoltTestsSchema returns the schema of the dolt_tests system table. This is used
// by Doltgres to update the dolt_tests schema using Doltgres types.
var GetDoltTestsSchema = doltTestsSchema

// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_tests system table.
func (tt *TestsTable) Schema() sql.Schema {
	return GetDoltTestsSchema()
}

func (tt *TestsTable) Collation() sql.CollationID {
	return sql.Collation_Default
}

// Partitions is a sql.Table interface function that returns a partition of the data.
func (tt *TestsTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
	if tt.backingTable == nil {
		// no backing table; return an empty iter.
		return index.SinglePartitionIterFromNomsMap(nil), nil
	}
	return tt.backingTable.Partitions(context)
}


Review comment (suggestion):
This is a bit of a one way door. We could change it  the future, but it would be best to get it right on the first pass.

I would think that `test_name` would be the only primary key, and the `test_group` would be a nullable column which you could you but wouldn't be required. Where is the spec for `dolt_test()` documented? How do people run individual tests? How do they run a group? How do they run all?

What is the spec on the text which goes into the test_assertion column? Seems like we are going to have strings like "> 42" and things like that, yeah? Ideally, we should be able to validate the string before insertion, but I don't see anything like that in this change.

Code after:
var _ sql.Table = (*TestsTable)(nil)
var _ sql.UpdatableTable = (*TestsTable)(nil)
var _ sql.DeletableTable = (*TestsTable)(nil)
var _ sql.InsertableTable = (*TestsTable)(nil)
var _ sql.ReplaceableTable = (*TestsTable)(nil)
var _ sql.IndexAddressableTable = (*TestsTable)(nil)

// TestsTable is the system table that stores test definitions.
type TestsTable struct {
	backingTable VersionableTable
}

func (tt *TestsTable) Name() string {
	return doltdb.TestsTableName
}

func (tt *TestsTable) String() string {
	return doltdb.TestsTableName
}

func doltTestsSchema() sql.Schema {
	return []*sql.Column{
		{Name: "test_name", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: true},
		{Name: "test_group", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: true},
		{Name: "test_query", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_type", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_comparator", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
		{Name: "assertion_value", Type: sqlTypes.Text, Source: doltdb.TestsTableName, PrimaryKey: false, Nullable: false},
	}
}

// GetDoltTestsSchema returns the schema of the dolt_tests system table. This is used
// by Doltgres to update the dolt_tests schema using Doltgres types.
var GetDoltTestsSchema = doltTestsSchema

// Schema is a sql.Table interface function that gets the sql.Schema of the dolt_tests system table.
func (tt *TestsTable) Schema() sql.Schema {
	return GetDoltTestsSchema()
}

func (tt *TestsTable) Collation() sql.CollationID {
	return sql.Collation_Default
}

// Partitions is a sql.Table interface function that returns a partition of the data.
func (tt *TestsTable) Partitions(context *sql.Context) (sql.PartitionIter, error) {
	if tt.backingTable == nil {
		// no backing table; return an empty iter.
		return index.SinglePartitionIterFromNomsMap(nil), nil
	}
	return tt.backingTable.Partitions(context)