-
Notifications
You must be signed in to change notification settings - Fork 9
/
main_test.go
53 lines (42 loc) · 1.06 KB
/
main_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
package main
import (
"testing"
"os"
"github.com/beplus/makeicon/app/helper/image-helper"
"image"
)
func TestSave(t *testing.T) {
os.RemoveAll("AppIcon")
save("test/icon.png")
// check folders after test
checkFolderExist(t, "AppIcon")
for _, item := range image_helper.IconResized {
checkFolderExist(t, "AppIcon"+item.Path+item.Name+".png")
// check image size
checkImageSize(t, "AppIcon"+item.Path+item.Name+".png", item.Width, item.Height)
}
os.RemoveAll("AppIcon")
}
func checkImageSize(t *testing.T, path string, width uint, height uint) {
file, err := os.Open(path)
defer file.Close()
if err != nil {
t.Fatal(err)
}
img, _, err := image.DecodeConfig(file)
if err != nil {
t.Fatalf("%s: %v !\n", path, err)
}
if (img.Width != int(width) || img.Height != int(height) || img.Width != img.Height) {
t.Fatalf("Image: %v\n has invalid size! \n", path)
}
}
func checkFolderExist(t *testing.T, folder string) {
stat, err := os.Stat(folder)
if err != nil {
t.Fatal(err)
}
if stat == nil {
t.Fatalf("%v folder was not created.", folder)
}
}