Skip to content

Commit 82e2d2e

Browse files
authored
Merge pull request #2836 from dolthub/fulghum/backup_restore_testing
2 parents d563fb6 + 9cb5799 commit 82e2d2e

4 files changed

Lines changed: 831 additions & 7 deletions

File tree

core/override_functions.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ func rootValueWalkAddrs(sm types.SerialMessage, cb func(addr hash.Hash) error) e
108108
return err
109109
}
110110
}
111+
// Walk all Doltgres root object fields (sequences, types, functions, procedures, triggers, extensions, casts).
112+
// Each field stores a 20-byte hash pointing to a prolly address map in the chunk store. Without walking these,
113+
// backup/restore (SyncRoots/PullChunks) will not copy the root object chunks and they will be absent after restore.
114+
for _, ros := range storage.RootObjectSerializations {
115+
addrBytes := ros.Bytes(&msg)
116+
if len(addrBytes) == 0 {
117+
continue
118+
}
119+
objAddr := hash.New(addrBytes)
120+
if !objAddr.IsEmpty() {
121+
if err = cb(objAddr); err != nil {
122+
return err
123+
}
124+
}
125+
}
111126
return nil
112127
}
113128

testing/go/auth_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,14 @@ func TestAuthTests(t *testing.T) {
11531153
// Each time a new Dolt procedure is introduced in a ScriptTest, it's grouped into a set of related procedures. Each set
11541154
// is separated by a new line.
11551155
func TestAuthDoltProcedures(t *testing.T) {
1156+
tempDir, err := os.MkdirTemp("", t.Name())
1157+
if err != nil {
1158+
t.Fatal(err)
1159+
}
1160+
t.Cleanup(func() { _ = os.RemoveAll(tempDir) })
1161+
authTestFireUrl := func(path string) string {
1162+
return "file://" + filepath.ToSlash(filepath.Join(tempDir, path))
1163+
}
11561164
RunScripts(t, []ScriptTest{
11571165
{
11581166
UseLocalFileSystem: true,
@@ -1395,6 +1403,11 @@ func TestAuthDoltProcedures(t *testing.T) {
13951403
authTestSkipAsSuper("select dolt_count_commits('--from=main', '--to=test');", []sql.Row{{"{0}"}}, ""),
13961404

13971405
authTestAssertAsSuper("select dolt_backup('remove', 'bak1');", []sql.Row{{"{0}"}}, ""),
1406+
authTestAssertAsSuper(fmt.Sprintf("select dolt_backup('add', 'bak2', '%s');", authTestFireUrl("bak2")), []sql.Row{{"{0}"}}, ""),
1407+
authTestAssertAsSuper("select dolt_backup('sync', 'bak2');", []sql.Row{{"{0}"}}, ""),
1408+
authTestAssertAsSuper(fmt.Sprintf("select dolt_backup('restore', '%s', 'restored_db');", authTestFireUrl("bak2")), []sql.Row{{"{0}"}}, ""),
1409+
authTestAssertAsSuper("drop database restored_db;", []sql.Row{}, ""),
1410+
authTestAssertAsSuper("select dolt_backup('remove', 'bak2');", []sql.Row{{"{0}"}}, ""),
13981411
authTestAssertAsSuper(fmt.Sprintf("select dolt_remote('add', 'origin', '%s');", authTestFireUrl("bak1")), []sql.Row{{"{0}"}}, ""),
13991412

14001413
authTestAssertAsSuper("select dolt_fetch('origin', 'main');", []sql.Row{{"{0}"}}, ""),
@@ -1504,6 +1517,8 @@ func TestAuthDoltProcedures(t *testing.T) {
15041517
authTestSkipAssertAsBasic("select dolt_count_commits('--from=main', '--to=test');", []sql.Row{{"{0}"}}, ""),
15051518

15061519
authTestAssertAsBasic("select dolt_backup('remove', 'bak1');", nil, functions.ErrDoltProcedurePermissionDenied.Error()),
1520+
authTestAssertAsBasic("select dolt_backup('sync', 'bak1');", nil, functions.ErrDoltProcedurePermissionDenied.Error()),
1521+
authTestAssertAsBasic(fmt.Sprintf("select dolt_backup('restore', '%s', 'restored_db');", authTestFireUrl("bak1")), nil, functions.ErrDoltProcedurePermissionDenied.Error()),
15071522
authTestAssertAsBasic(fmt.Sprintf("select dolt_remote('add', 'origin', '%s');", authTestFireUrl("bak1")), nil, functions.ErrDoltProcedurePermissionDenied.Error()),
15081523

15091524
authTestAssertAsBasic("select dolt_fetch('origin', 'main');", nil, functions.ErrDoltProcedurePermissionDenied.Error()),
@@ -1605,9 +1620,3 @@ func authTestGrantBasic(object string, privileges ...string) ScriptTestAssertion
16051620
Expected: []sql.Row{},
16061621
}
16071622
}
1608-
1609-
// authTestFireUrl returns a file:// URL path for a temp file.
1610-
func authTestFireUrl(path string) string {
1611-
path = filepath.Join(os.TempDir(), path)
1612-
return "file://" + filepath.ToSlash(filepath.Clean(path))
1613-
}

0 commit comments

Comments
 (0)