Files
sundynix-pets/pets-be/internal/admin/embed_test.go
T
Blizzard 8de48cb44d
ci-cd / verify (push) Successful in 1m48s
ci-cd / deploy (push) Skipped
Serve admin console at root path
2026-10-01 14:13:04 +08:00

37 lines
1.0 KiB
Go

package admin
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
"github.com/sundynix/pets-be/internal/config"
"github.com/sundynix/pets-be/internal/httpapi"
)
func TestAdminAtRootAndAPIRoutes(t *testing.T) {
gin.SetMode(gin.TestMode)
r := gin.New()
httpapi.New(nil, nil, &config.Config{}).Register(r)
Register(r)
for _, tc := range []struct {
path string
status int
body string
}{
{path: "/", status: http.StatusOK, body: "<div id=\"root\"></div>"},
{path: "/api/ping", status: http.StatusOK, body: "pong"},
{path: "/api/missing", status: http.StatusNotFound},
{path: "/assets/missing.js", status: http.StatusNotFound},
} {
recorder := httptest.NewRecorder()
r.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, tc.path, nil))
if recorder.Code != tc.status || (tc.body != "" && !strings.Contains(recorder.Body.String(), tc.body)) {
t.Errorf("GET %s: got %d %q, want %d containing %q", tc.path, recorder.Code, recorder.Body.String(), tc.status, tc.body)
}
}
}