mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08: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 {
|
||||
Orientation int
|
||||
Alpha bool
|
||||
Channels int
|
||||
Alpha bool
|
||||
Profile bool
|
||||
Type string
|
||||
Space string
|
||||
|
|
|
|||
|
|
@ -32,23 +32,36 @@ func TestSize(t *testing.T) {
|
|||
|
||||
func TestMetadata(t *testing.T) {
|
||||
files := []struct {
|
||||
name string
|
||||
format string
|
||||
name string
|
||||
format string
|
||||
orientation int
|
||||
alpha bool
|
||||
profile bool
|
||||
space string
|
||||
}{
|
||||
{"test.jpg", "jpeg"},
|
||||
{"test.png", "png"},
|
||||
{"test.webp", "webp"},
|
||||
{"test.jpg", "jpeg", 0, false, false, "bicubic"},
|
||||
{"test.png", "png", 0, true, false, "bicubic"},
|
||||
{"test.webp", "webp", 0, false, false, "bicubic"},
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
size, err := Metadata(readFile(file.name))
|
||||
metadata, err := Metadata(readFile(file.name))
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
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