diff options
author | David Symonds <dsymonds@golang.org> | 2009-10-05 04:08:24 -0700 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2009-10-05 04:08:24 -0700 |
commit | a3ce9fff79da30bcc57fdddc4feda3060b8e6877 (patch) | |
tree | f6f2e2b5dcd6e0e1693c20978de3f35dc9ce68c0 /src/pkg/archive/tar/writer_test.go | |
parent | 75df1a1c6c07eed1a469e24c1e18c2deff801b6c (diff) | |
download | golang-a3ce9fff79da30bcc57fdddc4feda3060b8e6877.tar.gz |
Add write support for the GNU tar binary numeric field extension.
R=rsc
APPROVED=rsc
DELTA=102 (89 added, 1 deleted, 12 changed)
OCL=35321
CL=35327
Diffstat (limited to 'src/pkg/archive/tar/writer_test.go')
-rw-r--r-- | src/pkg/archive/tar/writer_test.go | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/pkg/archive/tar/writer_test.go b/src/pkg/archive/tar/writer_test.go index 69f069ff3..cd67fedf0 100644 --- a/src/pkg/archive/tar/writer_test.go +++ b/src/pkg/archive/tar/writer_test.go @@ -9,6 +9,7 @@ import ( "fmt"; "io"; "testing"; + "testing/iotest"; ) type writerTestEntry struct { @@ -37,7 +38,7 @@ var writerTests = []*writerTest{ Uname: "dsymonds", Gname: "eng", }, - contents: `Kilts`, + contents: "Kilts", }, &writerTestEntry{ header: &Header{ @@ -55,6 +56,28 @@ var writerTests = []*writerTest{ }, } }, + // The truncated test file was produced using these commands: + // dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt + // tar -b 1 -c -f- /tmp/16gig.txt | dd bs=512 count=8 > writer-big.tar + &writerTest{ + file: "testdata/writer-big.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "tmp/16gig.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 16 << 30, + Mtime: 1254699560, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + // no contents + }, + }, + }, } // Render byte array in a two-character hexadecimal string, spaced for easy visual inspection. @@ -105,7 +128,7 @@ testLoop: } buf := new(bytes.Buffer); - tw := NewWriter(buf); + tw := NewWriter(iotest.TruncateWriter(buf, 4 << 10)); // only catch the first 4 KB for j, entry := range test.entries { if err := tw.WriteHeader(entry.header); err != nil { t.Errorf("test %d, entry %d: Failed writing header: %v", i, j, err); @@ -116,7 +139,10 @@ testLoop: continue testLoop } } - tw.Close(); + if err := tw.Close(); err != nil { + t.Errorf("test %d: Failed closing archive: %v", err); + continue testLoop + } actual := buf.Bytes(); if !bytes.Equal(expected, actual) { |