2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 14:56:29 +00:00
restic/backend/local_test.go

57 lines
1.6 KiB
Go
Raw Normal View History

2014-09-23 20:39:12 +00:00
package backend_test
import (
"fmt"
"io/ioutil"
"testing"
2015-03-28 10:50:23 +00:00
"github.com/restic/restic/backend/local"
2015-04-09 19:15:48 +00:00
. "github.com/restic/restic/test"
2014-09-23 20:39:12 +00:00
)
2015-03-28 10:50:23 +00:00
func setupLocalBackend(t *testing.T) *local.Local {
2014-12-05 20:45:49 +00:00
tempdir, err := ioutil.TempDir("", "restic-test-")
2015-04-09 19:15:48 +00:00
OK(t, err)
2014-09-23 20:39:12 +00:00
2015-03-28 10:50:23 +00:00
b, err := local.Create(tempdir)
2015-04-09 19:15:48 +00:00
OK(t, err)
2014-09-23 20:39:12 +00:00
t.Logf("created local backend at %s", tempdir)
return b
}
2015-03-28 10:50:23 +00:00
func teardownLocalBackend(t *testing.T, b *local.Local) {
2015-06-13 10:35:19 +00:00
if !TestCleanup {
2014-09-23 20:39:12 +00:00
t.Logf("leaving local backend at %s\n", b.Location())
return
}
2015-04-09 19:15:48 +00:00
OK(t, b.Delete())
2014-09-23 20:39:12 +00:00
}
2015-03-28 10:50:23 +00:00
func TestLocalBackend(t *testing.T) {
2014-09-23 20:39:12 +00:00
// test for non-existing backend
2015-03-28 10:50:23 +00:00
b, err := local.Open("/invalid-restic-test")
2015-04-09 19:15:48 +00:00
Assert(t, err != nil, "opening invalid repository at /invalid-restic-test should have failed, but err is nil")
Assert(t, b == nil, fmt.Sprintf("opening invalid repository at /invalid-restic-test should have failed, but b is not nil: %v", b))
2014-09-23 20:39:12 +00:00
s := setupLocalBackend(t)
defer teardownLocalBackend(t, s)
2014-09-23 20:39:12 +00:00
2014-12-21 14:57:41 +00:00
testBackend(s, t)
2014-09-23 20:39:12 +00:00
}
func TestLocalBackendCreationFailures(t *testing.T) {
b := setupLocalBackend(t)
defer teardownLocalBackend(t, b)
2014-09-23 20:39:12 +00:00
// test failure to create a new repository at the same location
2015-03-28 10:50:23 +00:00
b2, err := local.Create(b.Location())
2015-04-09 19:15:48 +00:00
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
2014-09-23 20:39:12 +00:00
// test failure to create a new repository at the same location without a config file
2015-03-28 10:50:23 +00:00
b2, err = local.Create(b.Location())
2015-04-09 19:15:48 +00:00
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
2014-09-23 20:39:12 +00:00
}