mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-16 10:55:54 -07:00
feat(#13): metadata tests
This commit is contained in:
parent
206a1efc66
commit
cdade0c27f
2 changed files with 21 additions and 8 deletions
|
|
@ -13,8 +13,8 @@ type ImageSize struct {
|
||||||
|
|
||||||
type ImageMetadata struct {
|
type ImageMetadata struct {
|
||||||
Orientation int
|
Orientation int
|
||||||
Alpha bool
|
|
||||||
Channels int
|
Channels int
|
||||||
|
Alpha bool
|
||||||
Profile bool
|
Profile bool
|
||||||
Type string
|
Type string
|
||||||
Space string
|
Space string
|
||||||
|
|
|
||||||
|
|
@ -32,23 +32,36 @@ func TestSize(t *testing.T) {
|
||||||
|
|
||||||
func TestMetadata(t *testing.T) {
|
func TestMetadata(t *testing.T) {
|
||||||
files := []struct {
|
files := []struct {
|
||||||
name string
|
name string
|
||||||
format string
|
format string
|
||||||
|
orientation int
|
||||||
|
alpha bool
|
||||||
|
profile bool
|
||||||
|
space string
|
||||||
}{
|
}{
|
||||||
{"test.jpg", "jpeg"},
|
{"test.jpg", "jpeg", 0, false, false, "bicubic"},
|
||||||
{"test.png", "png"},
|
{"test.png", "png", 0, true, false, "bicubic"},
|
||||||
{"test.webp", "webp"},
|
{"test.webp", "webp", 0, false, false, "bicubic"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
size, err := Metadata(readFile(file.name))
|
metadata, err := Metadata(readFile(file.name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot read the image: %#v", err)
|
t.Fatalf("Cannot read the image: %#v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size.Type != file.format {
|
if metadata.Type != file.format {
|
||||||
t.Fatalf("Unexpected image format: %s", file.format)
|
t.Fatalf("Unexpected image format: %s", file.format)
|
||||||
}
|
}
|
||||||
|
if metadata.Orientation != file.orientation {
|
||||||
|
t.Fatalf("Unexpected image orientation: %d != %d", metadata.Orientation, file.orientation)
|
||||||
|
}
|
||||||
|
if metadata.Alpha != file.alpha {
|
||||||
|
t.Fatalf("Unexpected image alpha: %s != ", metadata.Alpha, file.alpha)
|
||||||
|
}
|
||||||
|
if metadata.Profile != file.profile {
|
||||||
|
t.Fatalf("Unexpected image profile: %s != %s", metadata.Profile, file.profile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue