Serve embedded admin assets from root
ci-cd / verify (push) Successful in 1m31s
ci-cd / deploy (push) Skipped

This commit is contained in:
2026-10-01 14:23:50 +08:00
parent fd4f7708ba
commit 5688db4d63
2 changed files with 22 additions and 1 deletions
+17
View File
@@ -1,6 +1,7 @@
package admin
import (
"io/fs"
"net/http"
"net/http/httptest"
"strings"
@@ -16,6 +17,20 @@ func TestAdminAtRootAndAPIRoutes(t *testing.T) {
r := gin.New()
httpapi.New(nil, nil, &config.Config{}).Register(r)
Register(r)
assets, err := fs.ReadDir(distFS, "dist/assets")
if err != nil {
t.Fatal(err)
}
var script string
for _, asset := range assets {
if strings.HasSuffix(asset.Name(), ".js") {
script = "/assets/" + asset.Name()
break
}
}
if script == "" {
t.Fatal("admin bundle has no JavaScript asset")
}
for _, tc := range []struct {
path string
@@ -23,6 +38,8 @@ func TestAdminAtRootAndAPIRoutes(t *testing.T) {
body string
}{
{path: "/", status: http.StatusOK, body: "<div id=\"root\"></div>"},
{path: script, status: http.StatusOK},
{path: "/favicon.svg", status: http.StatusOK},
{path: "/api/ping", status: http.StatusOK, body: "pong"},
{path: "/api/missing", status: http.StatusNotFound},
{path: "/assets/missing.js", status: http.StatusNotFound},