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

Function TestRestore

backend/plugin/parser/tsql/restore_test.go:210–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

208}
209
210func TestRestore(t *testing.T) {
211 tests := []restoreCase{}
212
213 const (
214 record = false
215 )
216 var (
217 filepath = "test-data/test_restore.yaml"
218 )
219
220 a := require.New(t)
221 yamlFile, err := os.Open(filepath)
222 a.NoError(err)
223
224 byteValue, err := io.ReadAll(yamlFile)
225 a.NoError(yamlFile.Close())
226 a.NoError(err)
227 a.NoError(yaml.Unmarshal(byteValue, &tests))
228
229 for i, t := range tests {
230 result, err := GenerateRestoreSQL(context.Background(), base.RestoreContext{
231 GetDatabaseMetadataFunc: fixedMockDatabaseMetadataGetter,
232 }, t.Input, &store.PriorBackupDetail_Item{
233 SourceTable: &store.PriorBackupDetail_Item_Table{
234 Database: "instances/i1/databases/" + t.OriginalDatabase,
235 Schema: "dbo",
236 Table: t.OriginalTable,
237 },
238 TargetTable: &store.PriorBackupDetail_Item_Table{
239 Database: "instances/i1/databases/" + t.BackupDatabase,
240 Schema: t.BackupDatabase,
241 Table: t.BackupTable,
242 },
243 StartPosition: &store.Position{
244 Line: 1,
245 Column: 0,
246 },
247 EndPosition: &store.Position{
248 Line: math.MaxInt32,
249 Column: 1,
250 },
251 })
252 a.NoError(err)
253
254 if record {
255 tests[i].Result = result
256 } else {
257 a.Equal(t.Result, result, t.Input)
258 }
259 }
260 if record {
261 yamltest.Record(t, filepath, tests)
262 }
263}
264
265func fixedMockDatabaseMetadataGetter(_ context.Context, _ string, database string) (string, *model.DatabaseMetadata, error) {
266 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