-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_test.go
55 lines (52 loc) · 1.1 KB
/
hash_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
package seenit
import (
"image/png"
"os"
"testing"
)
func TestHaveSeen(t *testing.T) {
db := MockDatabase{Buckets: make(map[string]MockBucket, 0)}
hash := "thisisatesthash"
community := "test-community"
seen, err := HaveSeen(community, hash, &db)
if err != nil {
t.Fatalf(err.Error())
}
if seen {
t.Fatal("Hash incorrectly marked as seen")
}
_, hasBucket := db.Buckets[community]
if !hasBucket {
t.Fatalf("Bucket %q not added", community)
}
err = RecordHash(community, hash, &db)
if err != nil {
t.Fatal(err.Error())
}
seen, err = HaveSeen(community, hash, &db)
if err != nil {
t.Fatal(err.Error())
}
if !seen {
t.Fatal("Hash incorrectly marked as unseen")
}
}
func TestHash(t *testing.T) {
imageFile, err := os.Open("test_image.png")
defer imageFile.Close()
if err != nil {
t.Fatal(err.Error())
}
image, err := png.Decode(imageFile)
if err != nil {
t.Fatal(err.Error())
}
hash, err := ImageToHash(image)
if err != nil {
t.Fatal(err.Error())
}
expectedHash := "0080c0c0c0c08000"
if hash != expectedHash {
t.Fatalf("Expected hash %q, got %q", expectedHash, hash)
}
}