mirror of
https://github.com/restic/restic.git
synced 2025-12-04 00:21:46 +00:00
Add test for to prevent double create
This commit is contained in:
@@ -7,13 +7,14 @@ import (
|
||||
"github.com/restic/restic/backend/test"
|
||||
)
|
||||
|
||||
func TestLocalBackendCreate(t *testing.T) { test.Create(t) }
|
||||
func TestLocalBackendOpen(t *testing.T) { test.Open(t) }
|
||||
func TestLocalBackendLocation(t *testing.T) { test.Location(t) }
|
||||
func TestLocalBackendConfig(t *testing.T) { test.Config(t) }
|
||||
func TestLocalBackendGetReader(t *testing.T) { test.GetReader(t) }
|
||||
func TestLocalBackendLoad(t *testing.T) { test.Load(t) }
|
||||
func TestLocalBackendWrite(t *testing.T) { test.Write(t) }
|
||||
func TestLocalBackendGeneric(t *testing.T) { test.Generic(t) }
|
||||
func TestLocalBackendDelete(t *testing.T) { test.Delete(t) }
|
||||
func TestLocalBackendCleanup(t *testing.T) { test.Cleanup(t) }
|
||||
func TestLocalBackendCreate(t *testing.T) { test.Create(t) }
|
||||
func TestLocalBackendOpen(t *testing.T) { test.Open(t) }
|
||||
func TestLocalBackendCreateWithConfig(t *testing.T) { test.CreateWithConfig(t) }
|
||||
func TestLocalBackendLocation(t *testing.T) { test.Location(t) }
|
||||
func TestLocalBackendConfig(t *testing.T) { test.Config(t) }
|
||||
func TestLocalBackendGetReader(t *testing.T) { test.GetReader(t) }
|
||||
func TestLocalBackendLoad(t *testing.T) { test.Load(t) }
|
||||
func TestLocalBackendWrite(t *testing.T) { test.Write(t) }
|
||||
func TestLocalBackendGeneric(t *testing.T) { test.Generic(t) }
|
||||
func TestLocalBackendDelete(t *testing.T) { test.Delete(t) }
|
||||
func TestLocalBackendCleanup(t *testing.T) { test.Cleanup(t) }
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package local_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -15,28 +14,35 @@ var tempBackendDir string
|
||||
|
||||
//go:generate go run ../test/generate_backend_tests.go
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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-")
|
||||
err := createTempdir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Printf("created new test backend at %v\n", tempdir)
|
||||
tempBackendDir = tempdir
|
||||
|
||||
return local.Create(tempdir)
|
||||
return local.Create(tempBackendDir)
|
||||
}
|
||||
|
||||
test.OpenFn = func() (backend.Backend, error) {
|
||||
if tempBackendDir == "" {
|
||||
return nil, errors.New("repository not initialized")
|
||||
err := createTempdir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return local.Open(tempBackendDir)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user