-
Notifications
You must be signed in to change notification settings - Fork 0
/
gifsicle_test.go
77 lines (66 loc) · 1.66 KB
/
gifsicle_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
65
66
67
68
69
70
71
72
73
74
75
76
77
package gifsicle_test
import (
"image/gif"
"os"
"path"
"testing"
"github.com/munchpass/gifsicle-go"
"github.com/stretchr/testify/assert"
)
func validateGifBounds(t *testing.T, gifSource *gif.GIF, targetGifPath string) {
fTarget, err := os.Open(targetGifPath)
if !assert.Nil(t, err) {
t.FailNow()
}
defer fTarget.Close()
gifTarget, err := gif.DecodeAll(fTarget)
if !assert.Nil(t, err) {
t.FailNow()
}
assert.Equal(t, gifSource.Config.Height, gifTarget.Config.Height)
assert.Equal(t, gifSource.Config.Width, gifTarget.Config.Width)
}
// Checks that the target gif can be parsed properly and has the same bounds
// as the source GIF.
func validateGifFiles(t *testing.T, sourceGifPath string, targetGifPath string) {
//defer os.Remove("target.jpg")
fSource, err := os.Open(sourceGifPath)
if !assert.Nil(t, err) {
t.FailNow()
}
gifSource, err := gif.DecodeAll(fSource)
if !assert.Nil(t, err) {
t.FailNow()
}
validateGifBounds(t, gifSource, targetGifPath)
}
func TestGifsicleVersion(t *testing.T) {
g, err := gifsicle.NewGifsicle()
if !assert.Nil(t, err) {
t.FailNow()
}
v, err := g.Version()
if !assert.Nil(t, err) {
t.FailNow()
}
assert.NotEmpty(t, v)
t.Logf("version: %s\n", v)
}
func TestGifsicleRunFromFile(t *testing.T) {
g, err := gifsicle.NewGifsicle()
if !assert.Nil(t, err) {
t.FailNow()
}
sourceGif := path.Join("testfiles", "portrait_3mb.gif")
outputGif := path.Join("testoutput", "portrait_3mb_output.gif")
err = g.InputFile(sourceGif).
OutputFile(outputGif).
Lossy(80).
OptimizeLevel(gifsicle.OPTIMIZE_LEVEL_THREE).
Debug().
Run()
if !assert.Nil(t, err) {
t.FailNow()
}
validateGifFiles(t, sourceGif, outputGif)
}