Merge branch 'development' into Database-Schema-&-Models
Resolved conflicts by keeping Database-Schema-&-Models version which contains: - Complete Phase 7 documentation polish (ELI5 style) - GitHub Actions CI/CD workflows (Docker + Pages) - GHCR migration (replacing Docker Hub) - All backend and frontend improvements
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// HealthHandler responds with basic service metadata for uptime checks.
|
||||
func HealthHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"service": version.Name,
|
||||
"version": version.SemVer,
|
||||
"git_commit": version.GitCommit,
|
||||
"build_date": version.BuildDate,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/Wikid82/CaddyProxyManagerPlus/backend/internal/models"
|
||||
)
|
||||
|
||||
func setupTestRouter(t *testing.T) (*gin.Engine, *gorm.DB) {
|
||||
t.Helper()
|
||||
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.AutoMigrate(&models.ProxyHost{}))
|
||||
|
||||
h := NewProxyHostHandler(db)
|
||||
r := gin.New()
|
||||
api := r.Group("/api/v1")
|
||||
h.RegisterRoutes(api)
|
||||
|
||||
return r, db
|
||||
}
|
||||
|
||||
func TestProxyHostLifecycle(t *testing.T) {
|
||||
router, _ := setupTestRouter(t)
|
||||
|
||||
body := `{"name":"Media","domain":"media.example.com","target_scheme":"http","target_host":"media","target_port":32400}`
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/proxy-hosts", strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
router.ServeHTTP(resp, req)
|
||||
require.Equal(t, http.StatusCreated, resp.Code)
|
||||
|
||||
var created models.ProxyHost
|
||||
require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &created))
|
||||
require.Equal(t, "media.example.com", created.Domain)
|
||||
|
||||
listReq := httptest.NewRequest(http.MethodGet, "/api/v1/proxy-hosts", nil)
|
||||
listResp := httptest.NewRecorder()
|
||||
router.ServeHTTP(listResp, listReq)
|
||||
require.Equal(t, http.StatusOK, listResp.Code)
|
||||
|
||||
var hosts []models.ProxyHost
|
||||
require.NoError(t, json.Unmarshal(listResp.Body.Bytes(), &hosts))
|
||||
require.Len(t, hosts, 1)
|
||||
}
|
||||
Reference in New Issue
Block a user