-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
image_test.go
46 lines (40 loc) · 972 Bytes
/
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
package faker
import (
"fmt"
"image"
"io"
"strings"
"testing"
)
type ErrorRaiserPngEncoder struct {
err error
}
func (creator ErrorRaiserPngEncoder) Encode(_ io.Writer, _ image.Image) error {
return creator.err
}
func TestImage(t *testing.T) {
f := New()
value := f.Image().Image(100, 100)
Expect(t, fmt.Sprintf("%T", value), "*os.File")
Expect(t, strings.HasSuffix(value.Name(), ".png"), true, value.Name())
}
func TestImagePanicIfTempFileCreationFails(t *testing.T) {
f := New()
img := f.Image()
expected := fmt.Errorf("temp file creation failed")
img.TempFileCreator = ErrorRaiserTempFileCreator{err: expected}
defer func() {
Expect(t, recover(), expected)
}()
img.Image(100, 100)
}
func TestImagePanicIfEncodingFails(t *testing.T) {
f := New()
img := f.Image()
expected := fmt.Errorf("png encoding failed")
img.PngEncoder = ErrorRaiserPngEncoder{err: expected}
defer func() {
Expect(t, recover(), expected)
}()
img.Image(100, 100)
}