tests: Add append test
This commit is contained in:
parent
b835f83fd5
commit
3fef613591
33
main_test.go
33
main_test.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -145,6 +146,38 @@ func TestTruncate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAppend(t *testing.T) {
|
||||||
|
fn := plainDir + "append"
|
||||||
|
file, err := os.Create(fn)
|
||||||
|
if err != nil {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
data := []byte("testdata123456789") // length 17
|
||||||
|
var buf bytes.Buffer
|
||||||
|
var hashWant string
|
||||||
|
for i := 0; i <= 500; i++ {
|
||||||
|
file.Write(data)
|
||||||
|
buf.Write(data)
|
||||||
|
bin := md5.Sum(buf.Bytes())
|
||||||
|
hashWant = hex.EncodeToString(bin[:])
|
||||||
|
hashActual := md5fn(fn)
|
||||||
|
if hashWant != hashActual {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overwrite with the same data
|
||||||
|
// Hash must stay the same
|
||||||
|
file.Seek(0, 0)
|
||||||
|
for i := 0; i <= 500; i++ {
|
||||||
|
file.Write(data)
|
||||||
|
hashActual := md5fn(fn)
|
||||||
|
if hashWant != hashActual {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkStreamWrite(t *testing.B) {
|
func BenchmarkStreamWrite(t *testing.B) {
|
||||||
buf := make([]byte, 1024*1024)
|
buf := make([]byte, 1024*1024)
|
||||||
t.SetBytes(int64(len(buf)))
|
t.SetBytes(int64(len(buf)))
|
||||||
|
@ -70,11 +70,12 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) {
|
|||||||
cryptfs.Warn.Printf("read: ReadAt: %s\n", err.Error())
|
cryptfs.Warn.Printf("read: ReadAt: %s\n", err.Error())
|
||||||
return nil, fuse.ToStatus(err)
|
return nil, fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
cryptfs.Debug.Printf("ReadAt length=%d offset=%d -> n=%d len=%d\n", alignedLength, alignedOffset, n, len(ciphertext))
|
cryptfs.Debug.Printf("ReadAt offset=%d length=%d -> n=%d len=%d\n", alignedLength, alignedOffset, n, len(ciphertext))
|
||||||
|
|
||||||
// Decrypt it
|
// Decrypt it
|
||||||
plaintext, err := f.cfs.DecryptBlocks(ciphertext)
|
plaintext, err := f.cfs.DecryptBlocks(ciphertext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
cryptfs.Warn.Printf("Corrupt block at offset=%d\n", off + uint64(len(plaintext)))
|
||||||
cryptfs.Warn.Printf("doRead: returning IO error\n")
|
cryptfs.Warn.Printf("doRead: returning IO error\n")
|
||||||
return nil, fuse.EIO
|
return nil, fuse.EIO
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user