Test Invalid Chunk Store

This commit is contained in:
Sarah Jamie Lewis 2021-12-07 17:01:43 -08:00
parent 369a0bc809
commit e252422463
1 changed files with 20 additions and 1 deletions

View File

@ -28,7 +28,7 @@ func TestManifest(t *testing.T) {
t.Logf("%v", manifest)
// Try to tread the chunk
// Try to read the chunk
_, err = manifest.GetChunkBytes(1)
if err == nil {
t.Fatalf("chunk fetch should have thrown an error")
@ -43,6 +43,11 @@ func TestManifest(t *testing.T) {
t.Fatalf("chunk fetch error: %v", err)
}
_, err = manifest.GetChunkBytes(0)
if err != nil {
t.Fatalf("chunk fetch error: %v", err)
}
json, _ := json.Marshal(manifest)
t.Logf("%s", json)
@ -112,7 +117,21 @@ func TestManifestLarge(t *testing.T) {
t.Fatalf("could not store chunk %v %v", i, err)
}
// Attempt to store the chunk in an invalid position...
_, err = cwtchPngOutManifest.StoreChunk(uint64(i+1), contents)
if err == nil {
t.Fatalf("incorrect chunk store")
}
}
// Attempt to store an invalid chunk...should trigger an error
_, err = cwtchPngOutManifest.StoreChunk(uint64(len(cwtchPngManifest.Chunks)), []byte{0xff})
if err == nil {
t.Fatalf("incorrect chunk store")
}
err = cwtchPngOutManifest.VerifyFile()
if err != nil {
t.Fatalf("could not verify file %v", err)