-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcommon_test.go
102 lines (83 loc) · 2.38 KB
/
common_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package siva
import (
"bytes"
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type CommonSuite struct{}
var _ = Suite(&CommonSuite{})
func (s *CommonSuite) TestHashedWriter(c *C) {
buf := bytes.NewBuffer(nil)
w := newHashedWriter(buf)
n, err := w.Write([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(w.Checksum(), Equals, uint32(0x8c736521))
c.Assert(w.Position(), Equals, 3)
n, err = w.Write([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(w.Checksum(), Equals, uint32(0x647af61e))
c.Assert(w.Position(), Equals, 6)
}
func (s *CommonSuite) TestHashedWriterReset(c *C) {
buf := bytes.NewBuffer(nil)
w := newHashedWriter(buf)
n, err := w.Write([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(w.Checksum(), Equals, uint32(0x8c736521))
c.Assert(w.Position(), Equals, 3)
w.Reset()
n, err = w.Write([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(w.Checksum(), Equals, uint32(0x8c736521))
c.Assert(w.Position(), Equals, 3)
}
func (s *CommonSuite) TestHashedReader(c *C) {
buf := bytes.NewBuffer(nil)
_, err := buf.Write([]byte("foo"))
c.Assert(err, IsNil)
_, err = buf.Write([]byte("foo"))
c.Assert(err, IsNil)
r := newHashedReader(buf)
n, err := r.Read([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(r.Checkshum(), Equals, uint32(0x8c736521))
c.Assert(r.Position(), Equals, 3)
n, err = r.Read([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(r.Checkshum(), Equals, uint32(0x647af61e))
c.Assert(r.Position(), Equals, 6)
}
func (s *CommonSuite) TestHashedReaderReset(c *C) {
buf := bytes.NewBuffer(nil)
_, err := buf.Write([]byte("foo"))
c.Assert(err, IsNil)
_, err = buf.Write([]byte("foo"))
c.Assert(err, IsNil)
r := newHashedReader(buf)
n, err := r.Read([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(r.Checkshum(), Equals, uint32(0x8c736521))
c.Assert(r.Position(), Equals, 3)
r.Reset()
n, err = r.Read([]byte("foo"))
c.Assert(err, IsNil)
c.Assert(n, Equals, 3)
c.Assert(r.Checkshum(), Equals, uint32(0x8c736521))
c.Assert(r.Position(), Equals, 3)
}
type fileFixture struct {
Name, Body string
}
var files = []fileFixture{
{"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
{"readme.txt", "This archive contains some text files."},
{"todo.txt", "Get animal handling license."},
}