github.com/cloudberrydb/gpbackup@v1.0.3-0.20240118031043-5410fd45eed6/restore/restore_internal_test.go (about) 1 package restore 2 3 import ( 4 "github.com/cloudberrydb/gpbackup/toc" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("restore internal tests", func() { 11 Describe("editStatementsRedirectStatements", func() { 12 It("does not alter schemas if no redirect was specified", func() { 13 statements := []toc.StatementWithType{ 14 { // simple table 15 Schema: "foo", Name: "bar", ObjectType: "TABLE", 16 Statement: "\n\nCREATE TABLE foo.bar (\n\ti integer\n) DISTRIBUTED BY (i);\n", 17 }, 18 { // view with mulitple schema replacements 19 Schema: "foo", Name: "myview", ObjectType: "VIEW", 20 Statement: "\n\nCREATE VIEW foo.myview AS SELECT bar.i\n FROM foo.bar;\n", 21 }, 22 { // schema and table are the same name 23 Schema: "foo", Name: "foo", ObjectType: "TABLE", 24 Statement: "\n\nCREATE TABLE foo.foo (\n\ti integer\n) DISTRIBUTED BY (i);\n", 25 }, 26 } 27 28 editStatementsRedirectSchema(statements, "") 29 Expect(statements).To(Equal(statements)) 30 }) 31 It("changes schema in the sql statement", func() { 32 statements := []toc.StatementWithType{ 33 { // simple table 34 Schema: "foo", Name: "bar", ObjectType: "TABLE", 35 Statement: "\n\nCREATE TABLE foo.bar (\n\ti integer\n) DISTRIBUTED BY (i);\n", 36 }, 37 { // schema and table are the same name 38 Schema: "foo", Name: "foo", ObjectType: "TABLE", 39 Statement: "\n\nCREATE TABLE foo.foo (\n\ti integer\n) DISTRIBUTED BY (i);\n", 40 }, 41 } 42 43 editStatementsRedirectSchema(statements, "foo2") 44 45 expectedStatements := []toc.StatementWithType{ 46 { 47 Schema: "foo2", Name: "bar", ObjectType: "TABLE", 48 Statement: "\n\nCREATE TABLE foo2.bar (\n\ti integer\n) DISTRIBUTED BY (i);\n", 49 }, 50 { 51 Schema: "foo2", Name: "foo", ObjectType: "TABLE", 52 Statement: "\n\nCREATE TABLE foo2.foo (\n\ti integer\n) DISTRIBUTED BY (i);\n", 53 }, 54 } 55 Expect(statements).To(Equal(expectedStatements)) 56 }) 57 }) 58 })