/
thumb_test.go
45 lines (35 loc) · 1.05 KB
/
thumb_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
package main
import (
"testing"
assert "github.com/pilu/miniassert"
)
func TestThumbFromPath(t *testing.T) {
path := "/path/to/image/foo-20x40.png"
thumb, err := ThumbFromPath(path)
assert.Nil(t, err)
assert.Equal(t, path, thumb.Path)
assert.Equal(t, "/path/to/image", thumb.Dir)
assert.Equal(t, "foo", thumb.Name)
assert.Equal(t, ".png", thumb.Ext)
assert.Equal(t, "/path/to/image/foo.png", thumb.MainPath)
}
func TestParseThumbName(t *testing.T) {
path := "foo-20x40.png"
name, geometry, err := ParseThumbName(path)
assert.Nil(t, err)
assert.Equal(t, "foo", name)
assert.Equal(t, 20, geometry.Width)
assert.Equal(t, 40, geometry.Height)
path = "foo-xyz-20x40.png"
name, geometry, err = ParseThumbName(path)
assert.Nil(t, err)
assert.Equal(t, "foo-xyz", name)
assert.Equal(t, 20, geometry.Width)
assert.Equal(t, 40, geometry.Height)
path = "foo20x40.png" //bad filename
name, geometry, err = ParseThumbName(path)
assert.NotNil(t, err)
assert.Equal(t, "", name)
assert.Equal(t, 0, geometry.Width)
assert.Equal(t, 0, geometry.Height)
}