Remove all dot-imports

This commit is contained in:
Herbert
2017-10-02 15:06:39 +02:00
parent 1b5242b4f9
commit 3473c3f7b6
31 changed files with 598 additions and 601 deletions

View File

@@ -7,7 +7,7 @@ import (
"testing"
"github.com/restic/restic/internal/crypto"
. "github.com/restic/restic/internal/test"
rtest "github.com/restic/restic/internal/test"
"github.com/restic/chunker"
)
@@ -23,24 +23,24 @@ func TestEncryptDecrypt(t *testing.T) {
}
for _, size := range tests {
data := Random(42, size)
data := rtest.Random(42, size)
buf := make([]byte, size+crypto.Extension)
ciphertext, err := k.Encrypt(buf, data)
OK(t, err)
Assert(t, len(ciphertext) == len(data)+crypto.Extension,
rtest.OK(t, err)
rtest.Assert(t, len(ciphertext) == len(data)+crypto.Extension,
"ciphertext length does not match: want %d, got %d",
len(data)+crypto.Extension, len(ciphertext))
plaintext := make([]byte, len(ciphertext))
n, err := k.Decrypt(plaintext, ciphertext)
OK(t, err)
rtest.OK(t, err)
plaintext = plaintext[:n]
Assert(t, len(plaintext) == len(data),
rtest.Assert(t, len(plaintext) == len(data),
"plaintext length does not match: want %d, got %d",
len(data), len(plaintext))
Equals(t, plaintext, data)
rtest.Equals(t, plaintext, data)
}
}
@@ -50,21 +50,21 @@ func TestSmallBuffer(t *testing.T) {
size := 600
data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data)
OK(t, err)
rtest.OK(t, err)
ciphertext := make([]byte, size/2)
ciphertext, err = k.Encrypt(ciphertext, data)
// this must extend the slice
Assert(t, cap(ciphertext) > size/2,
rtest.Assert(t, cap(ciphertext) > size/2,
"expected extended slice, but capacity is only %d bytes",
cap(ciphertext))
// check for the correct plaintext
plaintext := make([]byte, len(ciphertext))
n, err := k.Decrypt(plaintext, ciphertext)
OK(t, err)
rtest.OK(t, err)
plaintext = plaintext[:n]
Assert(t, bytes.Equal(plaintext, data),
rtest.Assert(t, bytes.Equal(plaintext, data),
"wrong plaintext returned")
}
@@ -74,18 +74,18 @@ func TestSameBuffer(t *testing.T) {
size := 600
data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data)
OK(t, err)
rtest.OK(t, err)
ciphertext := make([]byte, 0, size+crypto.Extension)
ciphertext, err = k.Encrypt(ciphertext, data)
OK(t, err)
rtest.OK(t, err)
// use the same buffer for decryption
n, err := k.Decrypt(ciphertext, ciphertext)
OK(t, err)
rtest.OK(t, err)
ciphertext = ciphertext[:n]
Assert(t, bytes.Equal(ciphertext, data),
rtest.Assert(t, bytes.Equal(ciphertext, data),
"wrong plaintext returned")
}
@@ -95,20 +95,20 @@ func TestCornerCases(t *testing.T) {
// nil plaintext should encrypt to the empty string
// nil ciphertext should allocate a new slice for the ciphertext
c, err := k.Encrypt(nil, nil)
OK(t, err)
rtest.OK(t, err)
Assert(t, len(c) == crypto.Extension,
rtest.Assert(t, len(c) == crypto.Extension,
"wrong length returned for ciphertext, expected 0, got %d",
len(c))
// this should decrypt to nil
n, err := k.Decrypt(nil, c)
OK(t, err)
Equals(t, 0, n)
rtest.OK(t, err)
rtest.Equals(t, 0, n)
// test encryption for same slice, this should return an error
_, err = k.Encrypt(c, c)
Equals(t, crypto.ErrInvalidCiphertext, err)
rtest.Equals(t, crypto.ErrInvalidCiphertext, err)
}
func TestLargeEncrypt(t *testing.T) {
@@ -121,15 +121,15 @@ func TestLargeEncrypt(t *testing.T) {
for _, size := range []int{chunker.MaxSize, chunker.MaxSize + 1, chunker.MaxSize + 1<<20} {
data := make([]byte, size)
_, err := io.ReadFull(rand.Reader, data)
OK(t, err)
rtest.OK(t, err)
ciphertext, err := k.Encrypt(make([]byte, size+crypto.Extension), data)
OK(t, err)
rtest.OK(t, err)
plaintext, err := k.Decrypt([]byte{}, ciphertext)
OK(t, err)
rtest.OK(t, err)
Equals(t, plaintext, data)
rtest.Equals(t, plaintext, data)
}
}
@@ -145,7 +145,7 @@ func BenchmarkEncrypt(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := k.Encrypt(buf, data)
OK(b, err)
rtest.OK(b, err)
}
}
@@ -159,13 +159,13 @@ func BenchmarkDecrypt(b *testing.B) {
ciphertext := make([]byte, size+crypto.Extension)
ciphertext, err := k.Encrypt(ciphertext, data)
OK(b, err)
rtest.OK(b, err)
b.ResetTimer()
b.SetBytes(int64(size))
for i := 0; i < b.N; i++ {
_, err = k.Decrypt(plaintext, ciphertext)
OK(b, err)
rtest.OK(b, err)
}
}