-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathprocess_test.go
90 lines (83 loc) · 2.04 KB
/
process_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
78
79
80
81
82
83
84
85
86
87
88
89
90
package encoder
import (
"testing"
"webp_server_go/config"
"github.com/davidbyttow/govips/v2/vips"
)
func TestResizeImage(t *testing.T) {
img, _ := vips.Black(500, 500)
// Define the parameters for the test cases
testCases := []struct {
extraParams config.ExtraParams // Extra parameters
expectedH int // Expected height
expectedW int // Expected width
}{
// Tests for MaxHeight and MaxWidth
// Both extraParams.MaxHeight and extraParams.MaxWidth are 0
{
extraParams: config.ExtraParams{
MaxHeight: 0,
MaxWidth: 0,
},
expectedH: 500,
expectedW: 500,
},
// Both extraParams.MaxHeight and extraParams.MaxWidth are greater than 0, but the image size is smaller than the limits
{
extraParams: config.ExtraParams{
MaxHeight: 1000,
MaxWidth: 1000,
},
expectedH: 500,
expectedW: 500,
},
// Both extraParams.MaxHeight and extraParams.MaxWidth are greater than 0, and the image exceeds the limits
{
extraParams: config.ExtraParams{
MaxHeight: 200,
MaxWidth: 200,
},
expectedH: 200,
expectedW: 200,
},
// Only MaxHeight is set to 200
{
extraParams: config.ExtraParams{
MaxHeight: 200,
MaxWidth: 0,
},
expectedH: 200,
expectedW: 200,
},
// Test for Width and Height
{
extraParams: config.ExtraParams{
Width: 200,
Height: 200,
},
expectedH: 200,
expectedW: 200,
},
{
extraParams: config.ExtraParams{
Width: 200,
Height: 500,
},
expectedH: 500,
expectedW: 200,
},
}
// Iterate through the test cases and perform the tests
for _, tc := range testCases {
err := resizeImage(img, tc.extraParams)
if err != nil {
t.Errorf("resizeImage failed with error: %v", err)
}
// Verify if the adjusted image height and width match the expected values
actualH := img.Height()
actualW := img.Width()
if actualH != tc.expectedH || actualW != tc.expectedW {
t.Errorf("resizeImage failed: expected (%d, %d), got (%d, %d)", tc.expectedH, tc.expectedW, actualH, actualW)
}
}
}