Reduce time spent in tests

Make testing crypto functions with large buffers optional, use the flag
'-test.largecrypto'.
This commit is contained in:
Alexander Neumann 2015-01-13 09:04:30 +01:00
parent 48751e1935
commit 7f9e81431f
1 changed files with 12 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import (
var testPassword = "foobar"
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")
func setupBackend(t testing.TB) restic.Server {
tempdir, err := ioutil.TempDir("", "restic-test-")
@ -53,7 +54,12 @@ func TestEncryptDecrypt(t *testing.T) {
defer teardownBackend(t, s)
k := setupKey(t, s, testPassword)
for _, size := range []int{5, 23, 1 << 20, 7<<20 + 123} {
tests := []int{5, 23, 2<<18 + 23, 1 << 20}
if *testLargeCrypto {
tests = append(tests, 7<<20+123)
}
for _, size := range tests {
data := make([]byte, size)
f, err := os.Open("/dev/urandom")
ok(t, err)
@ -75,11 +81,15 @@ func TestEncryptDecrypt(t *testing.T) {
}
func TestLargeEncrypt(t *testing.T) {
if !*testLargeCrypto {
t.SkipNow()
}
s := setupBackend(t)
defer teardownBackend(t, s)
k := setupKey(t, s, testPassword)
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1} {
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
data := make([]byte, size)
f, err := os.Open("/dev/urandom")
ok(t, err)