From c48ede175a05d83bd05b2c7af34d22a98382727e Mon Sep 17 00:00:00 2001
From: viktorstrate <viktorstrate@gmail.com>
Date: Sat, 6 Nov 2021 13:01:01 +0100
Subject: [PATCH] Fix exif circular imports in tests

---
 api/routes/authenticate_routes_test.go   | 16 ++++++++--------
 api/scanner/exif/exif.go                 |  8 ++++----
 api/scanner/exif/exif_parser_external.go |  2 +-
 api/scanner/exif/exif_parser_internal.go |  6 +++++-
 api/scanner/exif/exif_test.go            | 11 ++++++-----
 5 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/api/routes/authenticate_routes_test.go b/api/routes/authenticate_routes_test.go
index 5677b1b..9f67b0b 100644
--- a/api/routes/authenticate_routes_test.go
+++ b/api/routes/authenticate_routes_test.go
@@ -88,8 +88,8 @@ func TestAuthenticateRoute(t *testing.T) {
 
 			assert.NoError(t, err)
 			assert.True(t, success)
-			assert.Equal(t, responseMessage, "success")
-			assert.Equal(t, responseStatus, http.StatusAccepted)
+			assert.Equal(t, "success", responseMessage)
+			assert.Equal(t, http.StatusAccepted, responseStatus)
 		})
 	})
 
@@ -103,8 +103,8 @@ func TestAuthenticateRoute(t *testing.T) {
 
 			assert.NoError(t, err)
 			assert.True(t, success)
-			assert.Equal(t, responseMessage, "success")
-			assert.Equal(t, responseStatus, http.StatusAccepted)
+			assert.Equal(t, "success", responseMessage)
+			assert.Equal(t, http.StatusAccepted, responseStatus)
 		})
 
 		t.Run("Request without access token", func(t *testing.T) {
@@ -114,8 +114,8 @@ func TestAuthenticateRoute(t *testing.T) {
 
 			assert.Error(t, err)
 			assert.False(t, success)
-			assert.Equal(t, responseMessage, "unauthorized")
-			assert.Equal(t, responseStatus, http.StatusForbidden)
+			assert.Equal(t, "unauthorized", responseMessage)
+			assert.Equal(t, http.StatusForbidden, responseStatus)
 		})
 
 		expire := time.Now().Add(time.Hour * 24 * 30)
@@ -139,8 +139,8 @@ func TestAuthenticateRoute(t *testing.T) {
 
 			assert.NoError(t, err)
 			assert.True(t, success)
-			assert.Equal(t, responseMessage, "success")
-			assert.Equal(t, responseStatus, http.StatusAccepted)
+			assert.Equal(t, "success", responseMessage)
+			assert.Equal(t, http.StatusAccepted, responseStatus)
 		})
 	})
 
diff --git a/api/scanner/exif/exif.go b/api/scanner/exif/exif.go
index 838fb10..06f509f 100644
--- a/api/scanner/exif/exif.go
+++ b/api/scanner/exif/exif.go
@@ -9,19 +9,19 @@ import (
 	"github.com/photoview/photoview/api/graphql/models"
 )
 
-type exifParser interface {
+type ExifParser interface {
 	ParseExif(media_path string) (*models.MediaEXIF, error)
 }
 
-var globalExifParser exifParser
+var globalExifParser ExifParser
 
 func InitializeEXIFParser() {
 	// Decide between internal or external Exif parser
-	exiftoolParser, err := newExiftoolParser()
+	exiftoolParser, err := NewExiftoolParser()
 
 	if err != nil {
 		log.Printf("Failed to get exiftool, using internal exif parser instead: %v\n", err)
-		globalExifParser = &internalExifParser{}
+		globalExifParser = NewInternalExifParser()
 	} else {
 		log.Println("Found exiftool")
 		globalExifParser = exiftoolParser
diff --git a/api/scanner/exif/exif_parser_external.go b/api/scanner/exif/exif_parser_external.go
index 29940fe..2d71391 100644
--- a/api/scanner/exif/exif_parser_external.go
+++ b/api/scanner/exif/exif_parser_external.go
@@ -15,7 +15,7 @@ type externalExifParser struct {
 	dataLoader *dataloader.ExiftoolLoader
 }
 
-func newExiftoolParser() (*externalExifParser, error) {
+func NewExiftoolParser() (ExifParser, error) {
 	et, err := exiftool.NewExiftool(exiftool.NoPrintConversion())
 
 	if err != nil {
diff --git a/api/scanner/exif/exif_parser_internal.go b/api/scanner/exif/exif_parser_internal.go
index 1cb8a42..11c8ef8 100644
--- a/api/scanner/exif/exif_parser_internal.go
+++ b/api/scanner/exif/exif_parser_internal.go
@@ -16,7 +16,11 @@ import (
 // internalExifParser is an exif parser that parses the media without the use of external tools
 type internalExifParser struct{}
 
-func (p *internalExifParser) ParseExif(media_path string) (returnExif *models.MediaEXIF, returnErr error) {
+func NewInternalExifParser() ExifParser {
+	return internalExifParser{}
+}
+
+func (p internalExifParser) ParseExif(media_path string) (returnExif *models.MediaEXIF, returnErr error) {
 	photoFile, err := os.Open(media_path)
 	if err != nil {
 		return nil, err
diff --git a/api/scanner/exif/exif_test.go b/api/scanner/exif/exif_test.go
index e586c2c..9c2d32a 100644
--- a/api/scanner/exif/exif_test.go
+++ b/api/scanner/exif/exif_test.go
@@ -1,4 +1,4 @@
-package exif
+package exif_test
 
 import (
 	"fmt"
@@ -9,6 +9,7 @@ import (
 
 	"github.com/barasher/go-exiftool"
 	"github.com/photoview/photoview/api/graphql/models"
+	"github.com/photoview/photoview/api/scanner/exif"
 	"github.com/photoview/photoview/api/test_utils"
 	"github.com/stretchr/testify/assert"
 )
@@ -22,18 +23,18 @@ func TestExifParsers(t *testing.T) {
 
 	parsers := []struct {
 		name   string
-		parser exifParser
+		parser exif.ExifParser
 	}{
 		{
 			name:   "internal",
-			parser: &internalExifParser{},
+			parser: exif.NewInternalExifParser(),
 		},
 	}
 
-	if externalParser, err := newExiftoolParser(); err == nil {
+	if externalParser, err := exif.NewExiftoolParser(); err == nil {
 		parsers = append(parsers, struct {
 			name   string
-			parser exifParser
+			parser exif.ExifParser
 		}{
 			name:   "external",
 			parser: externalParser,
