-
Notifications
You must be signed in to change notification settings - Fork 0
/
oshash_test.go
74 lines (68 loc) · 1.73 KB
/
oshash_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
package oshash
import (
"os"
"testing"
)
func fromFileTester(filename string, expected uint64, t *testing.T) {
f, err := os.Open(filename)
if err != nil {
t.Error(err)
}
h, err := FromFile(f)
if err != nil {
t.Error(err)
}
if h != expected {
t.Errorf("Expected %v, got %v", expected, h)
}
}
func TestFromFile(t *testing.T) {
fromFileTester("test/parrots.jpg", uint64(17604422328474205166), t)
// Tests for the OpenSubtitles reference files. These files are not
// included in the GitHub repository due to their large filesize, and so
// are commented out here, but you can download the files (and extract
// the 4 GB dummy.bin file from its RAR archive) for more thorough testing.
//
// http://www.opensubtitles.org/addons/avi/breakdance.avi
// fromFileTester("test/breakdance.avi", uint64(10242414353417707026), t)
//
// http://www.opensubtitles.org/addons/avi/dummy.rar
// fromFileTester("test/dummy.bin", uint64(7059239720196713467), t)
}
func TestFromFilepath(t *testing.T) {
expected := uint64(17604422328474205166)
h, err := FromFilepath("test/parrots.jpg")
if err != nil {
t.Error(err)
}
if h != expected {
t.Errorf("Expected %v, got %v", expected, h)
}
}
func TestFromBytes(t *testing.T) {
f, err := os.Open("test/parrots.jpg")
if err != nil {
t.Error(err)
}
info, err := os.Stat("test/parrots.jpg")
if err != nil {
t.Error(err)
}
buf := make([]byte, info.Size())
f.Read(buf)
h, err := FromBytes(buf)
if err != nil {
t.Error(err)
}
expected := uint64(17604422328474205166)
if h != expected {
t.Errorf("Expected %v, got %v", expected, h)
}
}
func TestSmallDataErrors(t *testing.T) {
buf := []byte("just a bit of data")
_, err := FromBytes(buf)
if err != ErrDataTooSmall {
t.Error(err)
}
}