Repository navigation
Expand file tree
/
Copy paththumb_test.go
More file actions
81 lines (71 loc) · 1.91 KB
/
Copy paththumb_test.go
File metadata and controls
81 lines (71 loc) · 1.91 KB
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
package main
import (
"fmt"
. "github.com/smartystreets/goconvey/convey"
"image/jpeg"
"os"
"testing"
)
func TestHasDesiredDimension(t *testing.T) {
Convey("Check if an image has the same desired dimension", t, func() {
Convey("if the given dimensions are different from the image dimension, return false", func() {
thumb := &Thumb{
width: 120,
height: 90,
desired_width: 10,
desired_height: 20,
}
result := thumb.HasDesiredDimension()
So(result, ShouldBeFalse)
})
Convey("if the given dimensions are the same as the image dimension, return true", func() {
thumb := &Thumb{
width: 120,
height: 90,
desired_width: 120,
desired_height: 90,
}
result := thumb.HasDesiredDimension()
So(result, ShouldBeTrue)
})
})
}
func TestDecodeIt(t *testing.T) {
Convey("Open an image and decode it", t, func() {
original_img := "test_images/120x90.jpg"
final_img := "test_images/decode.jpg"
Convey("if the desired dimensions are different as the original one, scale it", func() {
thumb := &Thumb{
img_name: original_img,
desired_width: 20,
desired_height: 10,
}
img, er := thumb.DecodeIt()
So(er, ShouldBeNil)
out, err := os.Create(final_img)
if err != nil {
panic(fmt.Sprintf("is not possible to create the file %s necessary for testing", final_img))
}
defer out.Close()
jpeg.Encode(out, img, nil)
final_file, err := os.Open(final_img)
if err != nil {
fmt.Println(err)
}
config, _ := jpeg.DecodeConfig(final_file)
So(config.Width, ShouldEqual, 20)
So(config.Height, ShouldEqual, 10)
})
})
}
func TestSetDimension(t *testing.T) {
Convey("set dimension of an image", t, func() {
original_img := "test_images/120x90.jpg"
thumb := &Thumb{
img_name: original_img,
}
thumb.SetDimension()
So(thumb.width, ShouldEqual, 120)
So(thumb.height, ShouldEqual, 90)
})
}