-
Notifications
You must be signed in to change notification settings - Fork 17
/
image_test.go
75 lines (67 loc) · 2.49 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package igdb
import (
"github.com/pkg/errors"
"testing"
)
// Mocked image arguments for testing.
const (
testImageID = "dfgkfivjrhcksyymh9vw"
testImageURL = "https://images.igdb.com/igdb/image/upload/t_screenshot_med/dfgkfivjrhcksyymh9vw.jpg"
testImageURL2x = "https://images.igdb.com/igdb/image/upload/t_screenshot_med_2x/dfgkfivjrhcksyymh9vw.jpg"
)
func TestSizedImageURL(t *testing.T) {
var tests = []struct {
name string
id string
size imageSize
ratio int
wantURL string
wantErr error
}{
{"Non-empty ID and valid single ratio", testImageID, SizeScreenshotMed, 1, testImageURL, nil},
{"Non-empty ID and valid double ratio", testImageID, SizeScreenshotMed, 2, testImageURL2x, nil},
{"Non-empty ID and invalid negative ratio", testImageID, SizeScreenshotHuge, -1, "", ErrPixelRatio},
{"Non-empty ID and invalid triple ratio", testImageID, SizeScreenshotBig, 3, "", ErrPixelRatio},
{"Empty ID and valid ratio", "", Size1080p, 1, "", ErrBlankID},
{"Empty ID and invalid 0 ratio", "", SizeMicro, 0, "", ErrBlankID},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
url, err := SizedImageURL(test.id, test.size, test.ratio)
if errors.Cause(err) != test.wantErr {
t.Errorf("got: <%v>, want: <%v>", errors.Cause(err), test.wantErr)
}
if url != test.wantURL {
t.Errorf("got: <%v>, want: <%v>", url, test.wantURL)
}
})
}
}
func TestImage_SizedURL(t *testing.T) {
var tests = []struct {
name string
image Image
size imageSize
ratio int
wantURL string
wantErr error
}{
{"Non-empty ID and valid single ratio", Image{ImageID: testImageID}, SizeScreenshotMed, 1, testImageURL, nil},
{"Non-empty ID and valid double ratio", Image{ImageID: testImageID}, SizeScreenshotMed, 2, testImageURL2x, nil},
{"Non-empty ID and invalid negative ratio", Image{ImageID: testImageID}, SizeScreenshotHuge, -1, "", ErrPixelRatio},
{"Non-empty ID and invalid triple ratio", Image{ImageID: testImageID}, SizeScreenshotBig, 3, "", ErrPixelRatio},
{"Empty ID and valid ratio", Image{}, Size1080p, 1, "", ErrBlankID},
{"Empty ID and invalid 0 ratio", Image{}, SizeMicro, 0, "", ErrBlankID},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
url, err := test.image.SizedURL(test.size, test.ratio)
if errors.Cause(err) != test.wantErr {
t.Errorf("got: <%v>, want: <%v>", errors.Cause(err), test.wantErr)
}
if url != test.wantURL {
t.Errorf("got: <%v>, want: <%v>", url, test.wantURL)
}
})
}
}