MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestRestore

Function TestRestore

backend/plugin/parser/pg/restore_test.go:28–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestRestore(t *testing.T) {
29 tests := []restoreCase{}
30
31 const (
32 record = false
33 )
34 var (
35 filepath = "test-data/test_restore.yaml"
36 )
37
38 a := require.New(t)
39 yamlFile, err := os.Open(filepath)
40 a.NoError(err)
41
42 byteValue, err := io.ReadAll(yamlFile)
43 a.NoError(yamlFile.Close())
44 a.NoError(err)
45 a.NoError(yaml.Unmarshal(byteValue, &tests))
46
47 for i, t := range tests {
48 result, err := GenerateRestoreSQL(context.Background(), base.RestoreContext{
49 GetDatabaseMetadataFunc: fixedMockDatabaseMetadataGetter,
50 }, t.Input, &store.PriorBackupDetail_Item{
51 SourceTable: &store.PriorBackupDetail_Item_Table{
52 Database: "instances/i1/databases/" + t.OriginalDatabase,
53 Schema: "public",
54 Table: t.OriginalTable,
55 },
56 TargetTable: &store.PriorBackupDetail_Item_Table{
57 Database: "instances/i1/databases/" + t.BackupDatabase,
58 Schema: t.BackupDatabase,
59 Table: t.BackupTable,
60 },
61 StartPosition: &store.Position{
62 Line: 1,
63 Column: 0,
64 },
65 EndPosition: &store.Position{
66 Line: math.MaxInt32,
67 Column: 1,
68 },
69 })
70 a.NoError(err)
71
72 if record {
73 tests[i].Result = result
74 } else {
75 a.Equal(t.Result, result, t.Input)
76 }
77 }
78 if record {
79 yamltest.Record(t, filepath, tests)
80 }
81}
82
83func fixedMockDatabaseMetadataGetter(_ context.Context, _ string, database string) (string, *model.DatabaseMetadata, error) {
84 return database, model.NewDatabaseMetadata(&store.DatabaseSchemaMetadata{

Callers

nothing calls this directly

Calls 6

RecordFunction · 0.92
UnmarshalMethod · 0.80
GenerateRestoreSQLFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected