mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
feat(metadata): add tests
This commit is contained in:
parent
69ceaab4d8
commit
6f3e935bbb
3 changed files with 614 additions and 1 deletions
59
metadata_test.go
Normal file
59
metadata_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package bimg
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSize(t *testing.T) {
|
||||
files := []struct {
|
||||
name string
|
||||
width int
|
||||
height int
|
||||
}{
|
||||
{"test.jpg", 1680, 1050},
|
||||
{"test.png", 400, 300},
|
||||
{"test.webp", 550, 368},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
size, err := Size(readFile(file.name))
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot read the image: %#v", err)
|
||||
}
|
||||
|
||||
if size.Width != file.width || size.Height != file.height {
|
||||
t.Fatalf("Unexpected image size: %dx%d", size.Width, size.Height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadata(t *testing.T) {
|
||||
files := []struct {
|
||||
name string
|
||||
format string
|
||||
}{
|
||||
{"test.jpg", "jpeg"},
|
||||
{"test.png", "png"},
|
||||
{"test.webp", "webp"},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
size, err := Metadata(readFile(file.name))
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot read the image: %#v", err)
|
||||
}
|
||||
|
||||
if size.Type != file.format {
|
||||
t.Fatalf("Unexpected image format: %s", file.format)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func readFile(file string) []byte {
|
||||
data, _ := os.Open(path.Join("fixtures", file))
|
||||
buf, _ := ioutil.ReadAll(data)
|
||||
return buf
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue