photoprism/internal/api/api_test.go
Vedhavyas Singareddi 38b9889ef2 Add context for graceful shutdown #112
see pull request #114
2019-06-03 22:58:15 +02:00

26 lines
649 B
Go

package api
import (
"net/http"
"net/http/httptest"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/config"
)
// API test helper
func NewApiTest() (app *gin.Engine, router *gin.RouterGroup, conf *config.Config) {
conf = config.TestConfig()
gin.SetMode(gin.TestMode)
app = gin.New()
router = app.Group("/api/v1")
return app, router, conf
}
// 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)
return w
}