mirror of https://github.com/talgo-cloud/bimg.git
parent
d471c49348
commit
ef10d7d7ec
@ -0,0 +1,20 @@
|
|||||||
|
package bimg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestImageResize(t *testing.T) {
|
||||||
|
data, _ := os.Open(path.Join("fixtures/test.jpg"))
|
||||||
|
buf, err := ioutil.ReadAll(data)
|
||||||
|
|
||||||
|
image := NewImage(buf)
|
||||||
|
|
||||||
|
buf, err = image.Resize(300, 240)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
package bimg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDeterminateImageType(t *testing.T) {
|
||||||
|
files := []struct {
|
||||||
|
name string
|
||||||
|
expected ImageType
|
||||||
|
}{
|
||||||
|
{"test.jpg", JPEG},
|
||||||
|
{"test.png", PNG},
|
||||||
|
{"test.webp", WEBP},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
img, _ := os.Open(path.Join("fixtures", file.name))
|
||||||
|
buf, _ := ioutil.ReadAll(img)
|
||||||
|
defer img.Close()
|
||||||
|
|
||||||
|
if DetermineImageType(buf) != file.expected {
|
||||||
|
t.Fatal("Image type is not valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeterminateImageTypeName(t *testing.T) {
|
||||||
|
files := []struct {
|
||||||
|
name string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{"test.jpg", "jpeg"},
|
||||||
|
{"test.png", "png"},
|
||||||
|
{"test.webp", "webp"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
img, _ := os.Open(path.Join("fixtures", file.name))
|
||||||
|
buf, _ := ioutil.ReadAll(img)
|
||||||
|
defer img.Close()
|
||||||
|
|
||||||
|
if DetermineImageTypeName(buf) != file.expected {
|
||||||
|
t.Fatal("Image type is not valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue