mirror of https://github.com/restic/restic.git
Correctly test for config file
This commit is contained in:
parent
b211f834fa
commit
0a457eafed
|
@ -57,7 +57,7 @@ func Create(dir string) (*Local, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test if config file already exists
|
// test if config file already exists
|
||||||
_, err := os.Lstat(backend.Paths.Config)
|
_, err := os.Lstat(filepath.Join(dir, backend.Paths.Config))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, errors.New("config file already exists")
|
return nil, errors.New("config file already exists")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/backend/local"
|
"github.com/restic/restic/backend/local"
|
||||||
. "github.com/restic/restic/test"
|
. "github.com/restic/restic/test"
|
||||||
)
|
)
|
||||||
|
@ -46,11 +47,13 @@ func TestLocalBackendCreationFailures(t *testing.T) {
|
||||||
b := setupLocalBackend(t)
|
b := setupLocalBackend(t)
|
||||||
defer teardownLocalBackend(t, b)
|
defer teardownLocalBackend(t, b)
|
||||||
|
|
||||||
|
// create a fake config file
|
||||||
|
blob, err := b.Create()
|
||||||
|
OK(t, err)
|
||||||
|
fmt.Fprintf(blob, "config\n")
|
||||||
|
OK(t, blob.Finalize(backend.Config, ""))
|
||||||
|
|
||||||
// test failure to create a new repository at the same location
|
// test failure to create a new repository at the same location
|
||||||
b2, err := local.Create(b.Location())
|
b2, err := local.Create(b.Location())
|
||||||
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
|
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
|
||||||
|
|
||||||
// test failure to create a new repository at the same location without a config file
|
|
||||||
b2, err = local.Create(b.Location())
|
|
||||||
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ func Create(dir string, program string, args ...string) (*SFTP, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test if config file already exists
|
// test if config file already exists
|
||||||
_, err = sftp.c.Lstat(backend.Paths.Config)
|
_, err = sftp.c.Lstat(filepath.Join(dir, backend.Paths.Config))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, errors.New("config file already exists")
|
return nil, errors.New("config file already exists")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue