diff --git a/internal/api/test.go b/internal/api/api_test.go similarity index 61% rename from internal/api/test.go rename to internal/api/api_test.go index c4ee8d340..ab1dd4b77 100644 --- a/internal/api/test.go +++ b/internal/api/api_test.go @@ -9,7 +9,8 @@ import ( "github.com/photoprism/photoprism/internal/test" ) -func NewTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config) { +// API test helper +func NewApiTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config) { conf = test.NewConfig() gin.SetMode(gin.TestMode) app = gin.New() @@ -19,7 +20,8 @@ func NewTest() (app *gin.Engine, router *gin.RouterGroup, conf photoprism.Config return app, router, conf } -func TestRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { +// See https://medium.com/@craigchilds94/testing-gin-json-responses-1f258ce3b0b1 +func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { req, _ := http.NewRequest(method, path, nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) diff --git a/internal/api/photos_test.go b/internal/api/photos_test.go index e7fc76870..970431963 100644 --- a/internal/api/photos_test.go +++ b/internal/api/photos_test.go @@ -8,31 +8,31 @@ import ( ) func TestGetPhotos(t *testing.T) { - app, router, conf := NewTest() + app, router, conf := NewApiTest() GetPhotos(router, conf) - result := TestRequest(app, "GET", "/api/v1/photos?count=10") + result := PerformRequest(app, "GET", "/api/v1/photos?count=10") assert.Equal(t, http.StatusOK, result.Code) } func TestLikePhoto(t *testing.T) { - app, router, conf := NewTest() + app, router, conf := NewApiTest() LikePhoto(router, conf) - result := TestRequest(app, "POST", "/api/v1/photos/1/like") + result := PerformRequest(app, "POST", "/api/v1/photos/1/like") assert.Equal(t, http.StatusAccepted, result.Code) } func TestDislikePhoto(t *testing.T) { - app, router, conf := NewTest() + app, router, conf := NewApiTest() DislikePhoto(router, conf) - result := TestRequest(app, "DELETE", "/api/v1/photos/1/like") + result := PerformRequest(app, "DELETE", "/api/v1/photos/1/like") assert.Equal(t, http.StatusAccepted, result.Code) } diff --git a/internal/frontend/config.go b/internal/frontend/config.go index 4be7a2b37..72dd15647 100644 --- a/internal/frontend/config.go +++ b/internal/frontend/config.go @@ -1,4 +1,4 @@ package frontend -// Config values for Web frontend +// HTTP client / Web UI config values type Config map[string]interface{} diff --git a/internal/models/file.go b/internal/models/file.go index abd3d6775..ba16881df 100644 --- a/internal/models/file.go +++ b/internal/models/file.go @@ -4,7 +4,7 @@ import ( "github.com/jinzhu/gorm" ) -// A file that belongs to a photo +// An image or sidecar file that belongs to a photo type File struct { gorm.Model Photo *Photo