mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
feat: support multiple outputs
This commit is contained in:
parent
d471c49348
commit
ef10d7d7ec
9 changed files with 220 additions and 58 deletions
50
type_test.go
Normal file
50
type_test.go
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue