From edb9bba671505c50a2e63e46ba5e2095cd7c5aff Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Sun, 12 Jul 2020 14:36:36 +0200 Subject: [PATCH] Backend: Add unit tests for internal/photoprism --- internal/entity/photo_fixtures.go | 2 +- internal/photoprism/filename_test.go | 19 +++++++++++++++++++ internal/photoprism/index_location.go | 20 -------------------- 3 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 internal/photoprism/filename_test.go delete mode 100644 internal/photoprism/index_location.go diff --git a/internal/entity/photo_fixtures.go b/internal/entity/photo_fixtures.go index ff75c0cb7..67ced2618 100644 --- a/internal/entity/photo_fixtures.go +++ b/internal/entity/photo_fixtures.go @@ -181,7 +181,7 @@ var PhotoFixtures = PhotoMap{ "Photo03": { ID: 1000003, PhotoUID: "pt9jtdre2lvl0yh0", - TakenAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC), + TakenAt: time.Date(2008, 1, 1, 1, 0, 0, 0, time.UTC), TakenAtLocal: time.Time{}, TakenSrc: "meta", PhotoTitle: "", diff --git a/internal/photoprism/filename_test.go b/internal/photoprism/filename_test.go new file mode 100644 index 000000000..5c166c59e --- /dev/null +++ b/internal/photoprism/filename_test.go @@ -0,0 +1,19 @@ +package photoprism + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestFileName(t *testing.T) { + t.Run("sidecar", func(t *testing.T) { + assert.Equal(t, ".photoprism/test.jpg", FileName("sidecar", "test.jpg")) + }) + t.Run("import", func(t *testing.T) { + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/import/test.jpg", FileName("import", "test.jpg")) + }) + t.Run("examples", func(t *testing.T) { + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets/examples/test.jpg", FileName("examples", "test.jpg")) + }) + +} diff --git a/internal/photoprism/index_location.go b/internal/photoprism/index_location.go deleted file mode 100644 index f41a292f7..000000000 --- a/internal/photoprism/index_location.go +++ /dev/null @@ -1,20 +0,0 @@ -package photoprism - -import ( - "github.com/jinzhu/gorm" - "github.com/photoprism/photoprism/internal/entity" - "github.com/photoprism/photoprism/pkg/txt" -) - -func (ind *Index) estimateLocation(photo *entity.Photo) { - var recentPhoto entity.Photo - - if result := ind.db.Unscoped().Order(gorm.Expr("ABS(DATEDIFF(taken_at, ?)) ASC", photo.TakenAt)).Preload("Place").First(&recentPhoto); result.Error == nil { - if recentPhoto.HasPlace() { - photo.Place = recentPhoto.Place - photo.PhotoCountry = photo.Place.PlaceCountry - photo.PlaceSrc = entity.SrcAuto - log.Debugf("index: approximate location is %s", txt.Quote(recentPhoto.Place.Label())) - } - } -}