-
Notifications
You must be signed in to change notification settings - Fork 9
/
image_test.go
60 lines (52 loc) · 1.25 KB
/
image_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
package php_test
import (
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io/ioutil"
"github.com/hyperjiang/php"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Image Functions", func() {
Describe("GetImageSize", func() {
It("happy flow", func() {
want := php.ImageInfo{
Width: 559,
Height: 533,
Format: "jpeg",
Mime: "image/jpeg",
}
got, err := php.GetImageSize("./fish.jpg")
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(want))
})
It("file not exist", func() {
_, err := php.GetImageSize("./not-exist-file")
Expect(err).To(HaveOccurred())
})
It("unknown format", func() {
_, err := php.GetImageSize("./LICENSE")
Expect(err).To(HaveOccurred())
})
})
Describe("GetImageSizeFromString", func() {
data1, _ := ioutil.ReadFile("./fish.jpg")
data2, _ := ioutil.ReadFile("./LICENSE")
It("happy flow", func() {
want := php.ImageInfo{
Width: 559,
Height: 533,
Format: "jpeg",
Mime: "image/jpeg",
}
got, err := php.GetImageSizeFromString(data1)
Expect(err).NotTo(HaveOccurred())
Expect(got).To(Equal(want))
})
It("unknown format", func() {
_, err := php.GetImageSizeFromString(data2)
Expect(err).To(HaveOccurred())
})
})
})