-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_reader_test.go
41 lines (31 loc) · 980 Bytes
/
hash_reader_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
package ioutils_test
import (
"bytes"
"io"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/koofr/go-ioutils"
)
var _ = Describe("HashReader", func() {
It("should calculate hash", func() {
br := bytes.NewReader([]byte("123"))
r := NewHashReader(br)
Expect(r.Hash()).To(Equal("d41d8cd98f00b204e9800998ecf8427e"))
n, err := r.Read([]byte{0})
Expect(n).To(Equal(1))
Expect(err).NotTo(HaveOccurred())
Expect(r.Hash()).To(Equal("c4ca4238a0b923820dcc509a6f75849b"))
n, err = r.Read([]byte{0})
Expect(n).To(Equal(1))
Expect(err).NotTo(HaveOccurred())
Expect(r.Hash()).To(Equal("c20ad4d76fe97759aa27a0c99bff6710"))
n, err = r.Read([]byte{0})
Expect(n).To(Equal(1))
Expect(err).NotTo(HaveOccurred())
Expect(r.Hash()).To(Equal("202cb962ac59075b964b07152d234b70"))
n, err = r.Read([]byte{0})
Expect(n).To(Equal(0))
Expect(err).To(Equal(io.EOF))
Expect(r.Hash()).To(Equal("202cb962ac59075b964b07152d234b70"))
})
})