Tests for USE of non-dolt dbs

This commit is contained in:
Zach Musgrave
2023-06-09 17:58:32 -07:00
parent 8dc1190f73
commit 2525de307d
2 changed files with 26 additions and 1 deletions

View File

@@ -972,7 +972,9 @@ func (d *DoltSession) SwitchWorkingSet(
func (d *DoltSession) UseDatabase(ctx *sql.Context, db sql.Database) error {
sdb, ok := db.(SqlDatabase)
if !ok {
return fmt.Errorf("expected a SqlDatabase, got %T", db)
// Could be an externally provided db such as `mysql` or `information_schema`, in which case there's nothing for
// this hook to do
return nil
}
branchState, ok, err := d.lookupDbState(ctx, sdb.RevisionQualifiedName())

View File

@@ -2855,3 +2855,26 @@ SQL
[ "$status" -eq 1 ]
[[ "$output" =~ "provided --use-db dba does not exist or is not a directory" ]] || false
}
@test "sql: USE information schema and mysql databases" {
run dolt sql <<SQL
USE information_schema;
show tables;
SQL
# spot check result
[ "$status" -eq 0 ]
[[ "$output" =~ "Database changed" ]] || false
[[ "$output" =~ "columns" ]] || false
run dolt sql <<SQL
USE mysql;
show tables;
SQL
# spot check result
[ "$status" -eq 0 ]
[[ "$output" =~ "Database changed" ]] || false
[[ "$output" =~ "role_edges" ]] || false
}