Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
517ebbb2
Commit
517ebbb2
authored
Nov 05, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt-ify src/pkg/archive
R=rsc
http://go/go-review/1018046
parent
eabcc981
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
15 deletions
+15
-15
writer_test.go
src/pkg/archive/tar/writer_test.go
+15
-15
No files found.
src/pkg/archive/tar/writer_test.go
View file @
517ebbb2
...
@@ -13,13 +13,13 @@ import (
...
@@ -13,13 +13,13 @@ import (
)
)
type
writerTestEntry
struct
{
type
writerTestEntry
struct
{
header
*
Header
;
header
*
Header
;
contents
string
;
contents
string
;
}
}
type
writerTest
struct
{
type
writerTest
struct
{
file
string
;
// filename of expected output
file
string
;
// filename of expected output
entries
[]
*
writerTestEntry
;
entries
[]
*
writerTestEntry
;
}
}
var
writerTests
=
[]
*
writerTest
{
var
writerTests
=
[]
*
writerTest
{
...
@@ -54,7 +54,7 @@ var writerTests = []*writerTest{
...
@@ -54,7 +54,7 @@ var writerTests = []*writerTest{
},
},
contents
:
"Google.com
\n
"
,
contents
:
"Google.com
\n
"
,
},
},
}
}
,
},
},
// The truncated test file was produced using these commands:
// The truncated test file was produced using these commands:
// dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt
// dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt
...
@@ -68,7 +68,7 @@ var writerTests = []*writerTest{
...
@@ -68,7 +68,7 @@ var writerTests = []*writerTest{
Mode
:
0640
,
Mode
:
0640
,
Uid
:
73025
,
Uid
:
73025
,
Gid
:
5000
,
Gid
:
5000
,
Size
:
16
<<
30
,
Size
:
16
<<
30
,
Mtime
:
1254699560
,
Mtime
:
1254699560
,
Typeflag
:
'0'
,
Typeflag
:
'0'
,
Uname
:
"dsymonds"
,
Uname
:
"dsymonds"
,
...
@@ -92,14 +92,14 @@ func bytestr(offset int, b []byte) string {
...
@@ -92,14 +92,14 @@ func bytestr(offset int, b []byte) string {
s
+=
fmt
.
Sprintf
(
" %02x"
,
ch
);
s
+=
fmt
.
Sprintf
(
" %02x"
,
ch
);
}
}
}
}
return
s
return
s
;
}
}
// Render a pseudo-diff between two blocks of bytes.
// Render a pseudo-diff between two blocks of bytes.
func
bytediff
(
a
[]
byte
,
b
[]
byte
)
string
{
func
bytediff
(
a
[]
byte
,
b
[]
byte
)
string
{
const
rowLen
=
32
;
const
rowLen
=
32
;
s
:=
fmt
.
Sprintf
(
"(%d bytes vs. %d bytes)
\n
"
,
len
(
a
),
len
(
b
));
s
:=
fmt
.
Sprintf
(
"(%d bytes vs. %d bytes)
\n
"
,
len
(
a
),
len
(
b
));
for
offset
:=
0
;
len
(
a
)
+
len
(
b
)
>
0
;
offset
+=
rowLen
{
for
offset
:=
0
;
len
(
a
)
+
len
(
b
)
>
0
;
offset
+=
rowLen
{
na
,
nb
:=
rowLen
,
rowLen
;
na
,
nb
:=
rowLen
,
rowLen
;
if
na
>
len
(
a
)
{
if
na
>
len
(
a
)
{
na
=
len
(
a
);
na
=
len
(
a
);
...
@@ -115,7 +115,7 @@ func bytediff(a []byte, b []byte) string {
...
@@ -115,7 +115,7 @@ func bytediff(a []byte, b []byte) string {
a
=
a
[
na
:
len
(
a
)];
a
=
a
[
na
:
len
(
a
)];
b
=
b
[
nb
:
len
(
b
)];
b
=
b
[
nb
:
len
(
b
)];
}
}
return
s
return
s
;
}
}
func
TestWriter
(
t
*
testing
.
T
)
{
func
TestWriter
(
t
*
testing
.
T
)
{
...
@@ -124,30 +124,30 @@ testLoop:
...
@@ -124,30 +124,30 @@ testLoop:
expected
,
err
:=
io
.
ReadFile
(
test
.
file
);
expected
,
err
:=
io
.
ReadFile
(
test
.
file
);
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"test %d: Unexpected error: %v"
,
i
,
err
);
t
.
Errorf
(
"test %d: Unexpected error: %v"
,
i
,
err
);
continue
continue
;
}
}
buf
:=
new
(
bytes
.
Buffer
);
buf
:=
new
(
bytes
.
Buffer
);
tw
:=
NewWriter
(
iotest
.
TruncateWriter
(
buf
,
4
<<
10
));
// only catch the first 4 KB
tw
:=
NewWriter
(
iotest
.
TruncateWriter
(
buf
,
4
<<
10
));
// only catch the first 4 KB
for
j
,
entry
:=
range
test
.
entries
{
for
j
,
entry
:=
range
test
.
entries
{
if
err
:=
tw
.
WriteHeader
(
entry
.
header
);
err
!=
nil
{
if
err
:=
tw
.
WriteHeader
(
entry
.
header
);
err
!=
nil
{
t
.
Errorf
(
"test %d, entry %d: Failed writing header: %v"
,
i
,
j
,
err
);
t
.
Errorf
(
"test %d, entry %d: Failed writing header: %v"
,
i
,
j
,
err
);
continue
testLoop
continue
testLoop
;
}
}
if
_
,
err
:=
io
.
WriteString
(
tw
,
entry
.
contents
);
err
!=
nil
{
if
_
,
err
:=
io
.
WriteString
(
tw
,
entry
.
contents
);
err
!=
nil
{
t
.
Errorf
(
"test %d, entry %d: Failed writing contents: %v"
,
i
,
j
,
err
);
t
.
Errorf
(
"test %d, entry %d: Failed writing contents: %v"
,
i
,
j
,
err
);
continue
testLoop
continue
testLoop
;
}
}
}
}
if
err
:=
tw
.
Close
();
err
!=
nil
{
if
err
:=
tw
.
Close
();
err
!=
nil
{
t
.
Errorf
(
"test %d: Failed closing archive: %v"
,
err
);
t
.
Errorf
(
"test %d: Failed closing archive: %v"
,
err
);
continue
testLoop
continue
testLoop
;
}
}
actual
:=
buf
.
Bytes
();
actual
:=
buf
.
Bytes
();
if
!
bytes
.
Equal
(
expected
,
actual
)
{
if
!
bytes
.
Equal
(
expected
,
actual
)
{
t
.
Errorf
(
"test %d: Incorrect result: (-=expected, +=actual)
\n
%v"
,
t
.
Errorf
(
"test %d: Incorrect result: (-=expected, +=actual)
\n
%v"
,
i
,
bytediff
(
expected
,
actual
));
i
,
bytediff
(
expected
,
actual
));
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment