From 1b4d6e27774c3acc44b211ddf65be1e3c3612943 Mon Sep 17 00:00:00 2001 From: Richard Anthony Date: Fri, 27 Jan 2023 19:07:28 +1100 Subject: [PATCH] feat: HTTP API Expose internal functions to allow for http api and or SDK --- internal/dump/common_test.go | 5 +++-- internal/test/helpers.go | 3 ++- sdk.go | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 sdk.go diff --git a/internal/dump/common_test.go b/internal/dump/common_test.go index 3ee9112af..38334c8cf 100644 --- a/internal/dump/common_test.go +++ b/internal/dump/common_test.go @@ -5,8 +5,8 @@ import ( "context" "testing" + _restic "github.com/restic/restic" "github.com/restic/restic/internal/archiver" - "github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" @@ -67,13 +67,14 @@ func WriteTest(t *testing.T, format string, cd CheckDump) { target: "/", }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() tmpdir, repo := prepareTempdirRepoSrc(t, tt.args) - arch := archiver.New(repo, fs.Track{FS: fs.Local{}}, archiver.Options{}) + arch := _restic.Archiver(repo) back := rtest.Chdir(t, tmpdir) defer back() diff --git a/internal/test/helpers.go b/internal/test/helpers.go index 93178ae10..967613648 100644 --- a/internal/test/helpers.go +++ b/internal/test/helpers.go @@ -12,6 +12,7 @@ import ( "runtime" "testing" + "github.com/restic/restic" "github.com/restic/restic/internal/errors" mrand "math/rand" @@ -194,7 +195,7 @@ func RemoveAll(t testing.TB, path string) { // TempDir returns a temporary directory that is removed by t.Cleanup, // except if TestCleanupTempDirs is set to false. func TempDir(t testing.TB) string { - tempdir, err := os.MkdirTemp(TestTempDir, "restic-test-") + tempdir, err := restic.ResticDir(TestTempDir, "restic-test-") if err != nil { t.Fatal(err) } diff --git a/sdk.go b/sdk.go new file mode 100644 index 000000000..50299ed04 --- /dev/null +++ b/sdk.go @@ -0,0 +1,17 @@ +package restic + +import ( + "os" + + "github.com/restic/restic/internal/archiver" + "github.com/restic/restic/internal/fs" + "github.com/restic/restic/internal/restic" +) + +func ResticDir(d string, n string) (string, error) { + return os.MkdirTemp(d, n) +} + +func Archiver(repo restic.Repository) *archiver.Archiver { + return archiver.New(repo, fs.Track{FS: fs.Local{}}, archiver.Options{}) +}