File: file_test.go

package info (click to toggle)
golang-github-spf13-afero 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 576 kB
  • sloc: makefile: 5
file content (43 lines) | stat: -rw-r--r-- 892 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
	}
}