forked from jaswdr/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lorem_flickr_test.go
55 lines (48 loc) · 1.65 KB
/
lorem_flickr_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
package faker
import (
"fmt"
"strings"
"testing"
)
func TestLoremFlickrImage(t *testing.T) {
f := New()
value := f.LoremFlickr().Image(300, 200, []string{}, "", false)
Expect(t, fmt.Sprintf("%T", value), "*os.File")
Expect(t, strings.HasSuffix(value.Name(), ".jpg"), true, value.Name())
}
func TestLoremFlickrImageWithPrefix(t *testing.T) {
f := New()
for _, prefix := range []string{"g", "p", "red", "green", "blue"} {
value := f.LoremFlickr().Image(300, 200, []string{}, prefix, false)
Expect(t, strings.HasSuffix(value.Name(), ".jpg"), true, value.Name())
}
}
func TestLoremFlickrImageWithCategories(t *testing.T) {
f := New()
value := f.LoremFlickr().Image(300, 200, []string{"cat", "dog"}, "", false)
Expect(t, fmt.Sprintf("%T", value), "*os.File")
Expect(t, strings.HasSuffix(value.Name(), ".jpg"), true, value.Name())
value = f.LoremFlickr().Image(300, 200, []string{"cat", "dog"}, "", true)
Expect(t, fmt.Sprintf("%T", value), "*os.File")
Expect(t, strings.HasSuffix(value.Name(), ".jpg"), true, value.Name())
}
func TestLoremFlickrImagePanicIfRequestFails(t *testing.T) {
f := New()
service := f.LoremFlickr()
expected := fmt.Errorf("request failed")
service.HTTPClient = ErrorRaiserHTTPClient{err: expected}
defer func() {
Expect(t, recover(), expected)
}()
service.Image(300, 200, []string{}, "", false)
}
func TestLoremFlickrImagePanicIfTempFileCreationFails(t *testing.T) {
f := New()
service := f.LoremFlickr()
expected := fmt.Errorf("temp file creation failed")
service.TempFileCreator = ErrorRaiserTempFileCreator{err: expected}
defer func() {
Expect(t, recover(), expected)
}()
service.Image(300, 200, []string{}, "", false)
}