2014-12-05 20:45:49 +00:00
|
|
|
package restic_test
|
2014-09-23 20:39:12 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2015-03-14 11:10:08 +00:00
|
|
|
"path/filepath"
|
2014-09-23 20:39:12 +00:00
|
|
|
"testing"
|
|
|
|
|
2014-12-05 20:45:49 +00:00
|
|
|
"github.com/restic/restic"
|
|
|
|
"github.com/restic/restic/backend"
|
2014-09-23 20:39:12 +00:00
|
|
|
)
|
|
|
|
|
2014-11-15 18:34:42 +00:00
|
|
|
var testPassword = "foobar"
|
2014-09-23 20:39:12 +00:00
|
|
|
var testCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
|
2015-01-13 08:04:30 +00:00
|
|
|
var testLargeCrypto = flag.Bool("test.largecrypto", false, "also test crypto functions with large payloads")
|
2015-02-21 15:53:14 +00:00
|
|
|
var testTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
|
2014-09-23 20:39:12 +00:00
|
|
|
|
2014-12-21 16:02:49 +00:00
|
|
|
func setupBackend(t testing.TB) restic.Server {
|
2015-02-21 15:53:14 +00:00
|
|
|
tempdir, err := ioutil.TempDir(*testTempDir, "restic-test-")
|
2014-09-23 20:39:12 +00:00
|
|
|
ok(t, err)
|
|
|
|
|
2015-03-14 11:10:08 +00:00
|
|
|
// create repository below temp dir
|
|
|
|
b, err := backend.CreateLocal(filepath.Join(tempdir, "repo"))
|
|
|
|
ok(t, err)
|
|
|
|
|
|
|
|
// set cache dir
|
|
|
|
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
|
2014-09-23 20:39:12 +00:00
|
|
|
ok(t, err)
|
|
|
|
|
2014-12-21 16:02:49 +00:00
|
|
|
return restic.NewServer(b)
|
2014-09-23 20:39:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 16:02:49 +00:00
|
|
|
func teardownBackend(t testing.TB, s restic.Server) {
|
2014-09-23 20:39:12 +00:00
|
|
|
if !*testCleanup {
|
2014-12-21 16:02:49 +00:00
|
|
|
l := s.Backend().(*backend.Local)
|
|
|
|
t.Logf("leaving local backend at %s\n", l.Location())
|
2014-09-23 20:39:12 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-12-21 16:02:49 +00:00
|
|
|
ok(t, s.Delete())
|
2014-09-23 20:39:12 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 16:02:49 +00:00
|
|
|
func setupKey(t testing.TB, s restic.Server, password string) *restic.Key {
|
|
|
|
k, err := restic.CreateKey(s, password)
|
2014-09-23 20:39:12 +00:00
|
|
|
ok(t, err)
|
|
|
|
|
2014-11-15 18:34:42 +00:00
|
|
|
return k
|
|
|
|
}
|
2014-09-23 20:39:12 +00:00
|
|
|
|
2014-11-15 18:34:42 +00:00
|
|
|
func TestRepo(t *testing.T) {
|
2014-12-21 16:02:49 +00:00
|
|
|
s := setupBackend(t)
|
|
|
|
defer teardownBackend(t, s)
|
|
|
|
_ = setupKey(t, s, testPassword)
|
2014-09-23 20:39:12 +00:00
|
|
|
}
|