From 676c1aa92a25c8a09bb6ed3ec0448f3cf3125317 Mon Sep 17 00:00:00 2001 From: Taylor Bantle Date: Fri, 23 Aug 2024 14:59:09 -0700 Subject: [PATCH] Add tests for branch interactions with schema --- testing/go/schemas_test.go | 103 +++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/testing/go/schemas_test.go b/testing/go/schemas_test.go index 2b90a20ed7..f0235218b2 100755 --- a/testing/go/schemas_test.go +++ b/testing/go/schemas_test.go @@ -542,6 +542,109 @@ var SchemaTests = []ScriptTest{ }, }, }, + { + Name: "with branches", + SetUpScript: []string{ + "CREATE SCHEMA myschema", + "SET search_path = 'myschema'", + "CREATE TABLE mytbl (pk BIGINT PRIMARY KEY, v1 BIGINT);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT active_branch();", + Expected: []sql.Row{{"main"}}, + }, + { + Query: "SELECT current_schemas(true);", + Expected: []sql.Row{ + {"{pg_catalog,myschema}"}, + }, + }, + { + Skip: true, // TODO: revision database not supported yet + Query: "SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'postgres/main';", + Expected: []sql.Row{ + {"myschema"}, + {"pg_catalog"}, + {"public"}, + {"information_schema"}, + }, + }, + { + Query: "SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'postgres';", + Expected: []sql.Row{ + {"myschema"}, + {"pg_catalog"}, + {"public"}, + {"information_schema"}, + }, + }, + { + Query: "SELECT * FROM mytbl;", + Expected: []sql.Row{}, + }, + { + Query: "SELECT schemaname, tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog';", + Expected: []sql.Row{ + {"myschema", "mytbl"}, + }, + }, + { + Query: "SELECT dolt_checkout('-b', 'newbranch')", + Expected: []sql.Row{{"{0,\"Switched to branch 'newbranch'\"}"}}, + }, + { + Skip: true, // TODO: ERROR: no schema has been selected to create in + Query: "CREATE TABLE mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);", + Expected: []sql.Row{}, + }, + { + Query: "CREATE SCHEMA newbranchschema;", + Expected: []sql.Row{}, + }, + { + Query: "SET search_path = 'newbranchschema';", + Expected: []sql.Row{}, + }, + { + Query: "CREATE TABLE mytbl2 (pk BIGINT PRIMARY KEY, v1 BIGINT);", + Expected: []sql.Row{}, + }, + { + Query: "SELECT current_schemas(true)", + Expected: []sql.Row{ + {"{pg_catalog,newbranchschema}"}, + }, + }, + { + Skip: true, // TODO: revision database not supported yet + Query: "SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'postgres/newbranch';", + Expected: []sql.Row{ + {"newbranchschema"}, + {"pg_catalog"}, + {"public"}, + {"information_schema"}, + }, + }, + { + Skip: true, // TODO: Why are pg_catalog and public not showing up? + Query: "SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'postgres';", + Expected: []sql.Row{ + {"newbranchschema"}, + {"pg_catalog"}, + {"public"}, + {"information_schema"}, + }, + }, + { + Skip: true, // TODO: Getting error "database schema not found: pg_catalog" + Query: "SELECT schemaname, tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog';", + Expected: []sql.Row{ + {"newbranchschema", "mytbl2"}, + }, + }, + }, + }, // More tests: // * alter table statements, when they work better // * AS OF (when supported)