feat: HTTP API

Expose internal functions to allow for http api and or SDK
This commit is contained in:
Richard Anthony 2023-01-27 19:07:28 +11:00
parent 619e243e60
commit 1b4d6e2777
3 changed files with 22 additions and 3 deletions

View File

@ -5,8 +5,8 @@ import (
"context" "context"
"testing" "testing"
_restic "github.com/restic/restic"
"github.com/restic/restic/internal/archiver" "github.com/restic/restic/internal/archiver"
"github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test"
@ -67,13 +67,14 @@ func WriteTest(t *testing.T, format string, cd CheckDump) {
target: "/", target: "/",
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
tmpdir, repo := prepareTempdirRepoSrc(t, tt.args) 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) back := rtest.Chdir(t, tmpdir)
defer back() defer back()

View File

@ -12,6 +12,7 @@ import (
"runtime" "runtime"
"testing" "testing"
"github.com/restic/restic"
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
mrand "math/rand" 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, // TempDir returns a temporary directory that is removed by t.Cleanup,
// except if TestCleanupTempDirs is set to false. // except if TestCleanupTempDirs is set to false.
func TempDir(t testing.TB) string { func TempDir(t testing.TB) string {
tempdir, err := os.MkdirTemp(TestTempDir, "restic-test-") tempdir, err := restic.ResticDir(TestTempDir, "restic-test-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

17
sdk.go Normal file
View File

@ -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{})
}