/
imageloc_test.go
64 lines (58 loc) · 1.32 KB
/
imageloc_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
package fotki
import (
"os"
"testing"
)
func TestGetImageKind(t *testing.T) {
type testRes struct {
path string
res ImageKind
}
tests := []testRes{
{"", NoImage},
{".jpg", IsImage},
{"A.JpG", IsImage},
{"B.JPEG", IsImage},
{"C.JPEG_", NoImage},
{"d.mp4", IsMovie},
{"e.avi", IsMovie},
}
for _, tr := range tests {
res := GetImageKind(tr.path)
if res != tr.res {
t.Errorf("Wrong GetImageKind(%s) = %v, must be %v", tr.path, res, tr.res)
}
}
}
func TestImageLocExtractDate(t *testing.T) {
type testRes struct {
path string
date ImageDate
}
tests := []testRes{
{"testdata/tmp.jpg", ImageDate{2012, 12, 10}},
{"testdata/img2016_02_17.jpg", ImageDate{2016, 02, 17}},
{"testdata/1455684141000.jpg", ImageDate{2016, 02, 17}},
}
for _, tr := range tests {
osinfo, err := os.Stat(tr.path)
if err != nil {
t.Errorf("image is not found %s\n", tr.path)
continue
}
loc := &ImageLoc{tr.path, osinfo, GetImageKind(tr.path)}
info, err := loc.ExtractDate()
if err != nil {
t.Errorf("could not get the date for %s: %s\n", tr.path, err.Error())
continue
}
if !os.SameFile(loc.info, info.info) {
t.Errorf("different info for %s\n", tr.path)
continue
}
if info.date != tr.date {
t.Errorf("wrong date found for %s: %v != %v\n", tr.path, info.date, tr.date)
continue
}
}
}