refactor: do not include test controller in production builds (#402)

Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
Alessandro (Ale) Segala
2025-03-29 15:11:25 -07:00
committed by GitHub
parent fc68cf7eb2
commit b3b43a56af
8 changed files with 48 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
//go:build e2etest
package controller
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/pocket-id/pocket-id/backend/internal/service"
)
func NewTestController(group *gin.RouterGroup, testService *service.TestService) {
testController := &TestController{TestService: testService}
group.POST("/test/reset", testController.resetAndSeedHandler)
}
type TestController struct {
TestService *service.TestService
}
func (tc *TestController) resetAndSeedHandler(c *gin.Context) {
if err := tc.TestService.ResetDatabase(); err != nil {
_ = c.Error(err)
return
}
if err := tc.TestService.ResetApplicationImages(); err != nil {
_ = c.Error(err)
return
}
if err := tc.TestService.SeedDatabase(); err != nil {
_ = c.Error(err)
return
}
if err := tc.TestService.ResetAppConfig(); err != nil {
_ = c.Error(err)
return
}
tc.TestService.SetJWTKeys()
c.Status(http.StatusNoContent)
}