-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy paththumbhash_test.go
More file actions
37 lines (31 loc) · 856 Bytes
/
Copy paththumbhash_test.go
File metadata and controls
37 lines (31 loc) · 856 Bytes
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
package thumbhash
import (
"encoding/base64"
"image"
_ "image/jpeg"
_ "image/png"
"os"
"testing"
)
func TestEncodeImage(t *testing.T) {
checkImage := func(expectedB64Hash, filePath string) {
file, err := os.Open(filePath)
if err != nil {
t.Fatalf("cannot open %q: %v", filePath, err)
}
defer file.Close()
img, _, err := image.Decode(file)
if err != nil {
t.Fatalf("cannot decode %q: %v", filePath, err)
}
hash := EncodeImage(img)
b64Hash := base64.StdEncoding.EncodeToString(hash)
if b64Hash != expectedB64Hash {
t.Errorf("hash of %q is %q but should be %q",
filePath, b64Hash, expectedB64Hash)
}
}
checkImage("1QcSHQRnh493V4dIh4eXh1h4kJUI", "data/sunrise.jpg")
checkImage("X5qGNQw7oElslqhGWfSE+Q6oJ1h2iHB2Rw==", "data/firefox.png")
checkImage("VvYRNQRod313B4h3eHhYiHeAiQUo", "data/large-sunrise.png")
}