1
Fork 0
photoview/api/scanner/exif/exif_test.go

110 lines
2.6 KiB
Go
Raw Normal View History

2021-11-06 13:01:01 +01:00
package exif_test
2021-04-22 21:37:59 +02:00
import (
2021-04-22 22:46:52 +02:00
"fmt"
2021-04-23 15:10:23 +02:00
"os"
2021-04-22 22:46:52 +02:00
"path"
2021-04-22 21:37:59 +02:00
"testing"
"time"
2021-04-22 22:46:52 +02:00
"github.com/barasher/go-exiftool"
"github.com/photoview/photoview/api/graphql/models"
2021-11-06 13:01:01 +01:00
"github.com/photoview/photoview/api/scanner/exif"
2021-04-23 15:10:23 +02:00
"github.com/photoview/photoview/api/test_utils"
2021-04-22 21:37:59 +02:00
"github.com/stretchr/testify/assert"
)
2021-04-23 15:10:23 +02:00
func TestMain(m *testing.M) {
os.Exit(test_utils.IntegrationTestRun(m))
}
2021-04-22 21:37:59 +02:00
func TestExifParsers(t *testing.T) {
2021-04-23 15:10:23 +02:00
test_utils.FilesystemTest(t)
2021-04-22 21:37:59 +02:00
parsers := []struct {
name string
2021-11-06 13:01:01 +01:00
parser exif.ExifParser
2021-04-22 21:37:59 +02:00
}{
{
name: "internal",
2021-11-06 13:01:01 +01:00
parser: exif.NewInternalExifParser(),
2021-04-22 21:37:59 +02:00
},
}
2021-11-06 13:01:01 +01:00
if externalParser, err := exif.NewExiftoolParser(); err == nil {
parsers = append(parsers, struct {
name string
2021-11-06 13:01:01 +01:00
parser exif.ExifParser
}{
2021-04-22 21:37:59 +02:00
name: "external",
parser: externalParser,
})
2021-04-22 21:37:59 +02:00
}
2021-04-22 22:46:52 +02:00
images := []struct {
path string
assert func(t *testing.T, exif *models.MediaEXIF)
}{
{
path: "./test_data/bird.jpg",
assert: func(t *testing.T, exif *models.MediaEXIF) {
2022-03-28 17:08:30 +02:00
assert.EqualValues(t, *exif.Description, "Photo of a Bird")
2021-04-22 22:46:52 +02:00
assert.WithinDuration(t, *exif.DateShot, time.Unix(1336318784, 0).UTC(), time.Minute)
2021-04-22 21:37:59 +02:00
assert.EqualValues(t, *exif.Camera, "Canon EOS 600D")
assert.EqualValues(t, *exif.Maker, "Canon")
assert.WithinDuration(t, *exif.DateShot, time.Unix(1336318784, 0).UTC(), time.Minute)
assert.InDelta(t, *exif.Exposure, 1.0/4000.0, 0.0001)
2021-04-22 21:37:59 +02:00
assert.EqualValues(t, *exif.Aperture, 6.3)
assert.EqualValues(t, *exif.Iso, 800)
assert.EqualValues(t, *exif.FocalLength, 300)
assert.EqualValues(t, *exif.Flash, 16)
assert.EqualValues(t, *exif.Orientation, 1)
assert.InDelta(t, *exif.GPSLatitude, 65.01681388888889, 0.0001)
assert.InDelta(t, *exif.GPSLongitude, 25.466863888888888, 0.0001)
2021-04-22 22:46:52 +02:00
},
},
{
path: "./test_data/stripped.jpg",
assert: func(t *testing.T, exif *models.MediaEXIF) {
assert.Nil(t, exif)
},
},
{
path: "./test_data/bad-exif.jpg",
assert: func(t *testing.T, exif *models.MediaEXIF) {
assert.Nil(t, exif.Exposure)
},
},
2021-04-22 22:46:52 +02:00
}
for _, p := range parsers {
for _, img := range images {
t.Run(fmt.Sprintf("%s:%s", p.name, path.Base(img.path)), func(t *testing.T) {
if p.name == "external" {
_, err := exiftool.NewExiftool()
if err != nil {
t.Skip("failed to get exiftool, skipping test")
}
}
exif, err := p.parser.ParseExif(img.path)
if assert.NoError(t, err) {
img.assert(t, exif)
}
})
}
2021-04-22 21:37:59 +02:00
}
}
// func TestExternalExifParser(t *testing.T) {
// parser := externalExifParser{}
// exif, err := parser.ParseExif((bird_path))
// if assert.NoError(t, err) {
// assert.Equal(t, exif, &bird_exif)
// }
// }