2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-15 09:44:15 +00:00
restic/backend/local/local_test.go

60 lines
1.0 KiB
Go
Raw Normal View History

2016-01-23 16:08:03 +00:00
package local_test
import (
"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
2016-01-23 17:07:15 +00:00
func createTempdir() error {
if tempBackendDir != "" {
return nil
}
tempdir, err := ioutil.TempDir("", "restic-local-test-")
if err != nil {
return err
}
fmt.Printf("created new test backend at %v\n", tempdir)
tempBackendDir = tempdir
return nil
}
2016-01-23 16:08:03 +00:00
func init() {
test.CreateFn = func() (backend.Backend, error) {
2016-01-23 17:07:15 +00:00
err := createTempdir()
2016-01-23 16:08:03 +00:00
if err != nil {
return nil, err
}
2016-01-23 17:07:15 +00:00
return local.Create(tempBackendDir)
2016-01-23 16:08:03 +00:00
}
test.OpenFn = func() (backend.Backend, error) {
2016-01-23 17:07:15 +00:00
err := createTempdir()
if err != nil {
return nil, err
2016-01-23 16:08:03 +00:00
}
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
}
}