Add end-to-end replication/restore testing

This commit is contained in:
Ben Johnson
2022-01-14 15:31:04 -07:00
parent f308e0b154
commit 84d08f547a
27 changed files with 755 additions and 117 deletions

View File

@@ -1,12 +1,13 @@
package testingutil
import (
"io"
"os"
"testing"
)
// MustReadFile reads all data from filename. Fail on error.
func MustReadFile(tb testing.TB, filename string) []byte {
// ReadFile reads all data from filename. Fail on error.
func ReadFile(tb testing.TB, filename string) []byte {
tb.Helper()
b, err := os.ReadFile(filename)
if err != nil {
@@ -15,6 +16,26 @@ func MustReadFile(tb testing.TB, filename string) []byte {
return b
}
// CopyFile copies all data from src to dst. Fail on error.
func CopyFile(tb testing.TB, src, dst string) {
tb.Helper()
r, err := os.Open(src)
if err != nil {
tb.Fatal(err)
}
defer r.Close()
w, err := os.Create(dst)
if err != nil {
tb.Fatal(err)
}
defer w.Close()
if _, err := io.Copy(w, r); err != nil {
tb.Fatal(err)
}
}
// Getpwd returns the working directory. Fail on error.
func Getwd(tb testing.TB) string {
tb.Helper()