mirror of
https://github.com/restic/restic.git
synced 2025-12-04 00:21:46 +00:00
Implement package-local tests
This commit is contained in:
20
backend/local/backend_test.go
Normal file
20
backend/local/backend_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// DO NOT EDIT!
|
||||
// generated at 2016-23-01 17:06:38 +0100 CET
|
||||
package local_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/backend/test"
|
||||
)
|
||||
|
||||
func TestCreate(t *testing.T) { test.Create(t) }
|
||||
func TestOpen(t *testing.T) { test.Open(t) }
|
||||
func TestLocation(t *testing.T) { test.Location(t) }
|
||||
func TestConfig(t *testing.T) { test.Config(t) }
|
||||
func TestGetReader(t *testing.T) { test.GetReader(t) }
|
||||
func TestLoad(t *testing.T) { test.Load(t) }
|
||||
func TestWrite(t *testing.T) { test.Write(t) }
|
||||
func TestGeneric(t *testing.T) { test.Generic(t) }
|
||||
func TestDelete(t *testing.T) { test.Delete(t) }
|
||||
func TestCleanup(t *testing.T) { test.Cleanup(t) }
|
||||
@@ -226,6 +226,10 @@ func (b *Local) GetReader(t backend.Type, name string, offset, length uint) (io.
|
||||
// Load returns the data stored in the backend for h at the given offset
|
||||
// and saves it in p. Load has the same semantics as io.ReaderAt.
|
||||
func (b *Local) Load(h backend.Handle, p []byte, off int64) (n int, err error) {
|
||||
if err := h.Valid(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
f, err := os.Open(filename(b.p, h.Type, h.Name))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
53
backend/local/local_test.go
Normal file
53
backend/local/local_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package local_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/backend/local"
|
||||
"github.com/restic/restic/backend/test"
|
||||
)
|
||||
|
||||
var tempBackendDir string
|
||||
|
||||
//go:generate go run ../test/generate_backend_tests.go
|
||||
|
||||
func init() {
|
||||
test.CreateFn = func() (backend.Backend, error) {
|
||||
if tempBackendDir != "" {
|
||||
return nil, errors.New("temporary local backend dir already exists")
|
||||
}
|
||||
|
||||
tempdir, err := ioutil.TempDir("", "restic-local-test-")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Printf("created new test backend at %v\n", tempdir)
|
||||
tempBackendDir = tempdir
|
||||
|
||||
return local.Create(tempdir)
|
||||
}
|
||||
|
||||
test.OpenFn = func() (backend.Backend, error) {
|
||||
if tempBackendDir == "" {
|
||||
return nil, errors.New("repository not initialized")
|
||||
}
|
||||
|
||||
return local.Open(tempBackendDir)
|
||||
}
|
||||
|
||||
test.CleanupFn = func() error {
|
||||
if tempBackendDir == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("removing test backend at %v\n", tempBackendDir)
|
||||
err := os.RemoveAll(tempBackendDir)
|
||||
tempBackendDir = ""
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user