mirror of https://github.com/talgo-cloud/bimg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
900 B
51 lines
900 B
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")
|
|
}
|
|
}
|
|
}
|