1
0
mirror of https://github.com/restic/restic.git synced 2024-07-03 08:50:53 +02:00
restic/key_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

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