-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failing test for reading a small zip file
- Loading branch information
1 parent
1524d0a
commit fc99a5d
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package zipfs | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestFileRead(t *testing.T) { | ||
zrc, err := zip.OpenReader("testdata/small.zip") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
zfs := New(&zrc.Reader) | ||
f, err := zfs.Open("smallFile") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
info, err := f.Stat() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
chunkSize := info.Size() * 2 // read with extra large buffer | ||
|
||
buf := make([]byte, chunkSize) | ||
n, err := f.Read(buf) | ||
if err != io.EOF { | ||
t.Fatal("Failed to read file to completion:", err) | ||
} | ||
if n != int(info.Size()) { | ||
t.Errorf("Expected read length to be %d, found: %d", info.Size(), n) | ||
} | ||
|
||
// read a second time to check f.offset and f.buf are correct | ||
buf = make([]byte, chunkSize) | ||
n, err = f.Read(buf) | ||
if err != io.EOF { | ||
t.Fatal("Failed to read a fully read file:", err) | ||
} | ||
if n != 0 { | ||
t.Errorf("Expected read length to be 0, found: %d", n) | ||
} | ||
} |
Binary file not shown.