mirror of
https://github.com/golang/go
synced 2024-11-11 22:50:22 -07:00
zip: add a test for the previous >65k files fix
This surprisingly takes 30 seconds on my fast machine so disabling by default. Need to optimize the Writer at some point. R=golang-dev, r, r CC=golang-dev https://golang.org/cl/4815048
This commit is contained in:
parent
a667e44e75
commit
8fdc2851e4
57
src/pkg/archive/zip/zip_test.go
Normal file
57
src/pkg/archive/zip/zip_test.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Tests that involve both reading and writing.
|
||||||
|
|
||||||
|
package zip
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stringReaderAt string
|
||||||
|
|
||||||
|
func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) {
|
||||||
|
if off >= int64(len(s)) {
|
||||||
|
return 0, os.EOF
|
||||||
|
}
|
||||||
|
n = copy(p, s[off:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOver65kFiles(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Logf("slow test; skipping")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
w := NewWriter(buf)
|
||||||
|
const nFiles = (1 << 16) + 42
|
||||||
|
for i := 0; i < nFiles; i++ {
|
||||||
|
_, err := w.Create(fmt.Sprintf("%d.dat", i))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("creating file %d: %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := w.Close(); err != nil {
|
||||||
|
t.Fatalf("Writer.Close: %v", err)
|
||||||
|
}
|
||||||
|
rat := stringReaderAt(buf.String())
|
||||||
|
zr, err := NewReader(rat, int64(len(rat)))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("NewReader: %v", err)
|
||||||
|
}
|
||||||
|
if got := len(zr.File); got != nFiles {
|
||||||
|
t.Fatalf("File contains %d files, want %d", got, nFiles)
|
||||||
|
}
|
||||||
|
for i := 0; i < nFiles; i++ {
|
||||||
|
want := fmt.Sprintf("%d.dat", i)
|
||||||
|
if zr.File[i].Name != want {
|
||||||
|
t.Fatalf("File(%d) = %q, want %q", i, zr.File[i].Name, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user