feat: 推广 V3.5 实时氢耗并完善导出

This commit is contained in:
lingniu
2026-09-04 15:42:02 +08:00
parent a26179c8fe
commit e402eb5e60
53 changed files with 2855 additions and 320 deletions
@@ -0,0 +1,45 @@
package static
import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
func TestHandlerDisablesCachingForApplicationShell(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "index.html"), []byte("index"), 0o600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "app-config.js"), []byte("config"), 0o600); err != nil {
t.Fatal(err)
}
handler := Handler(dir, http.NotFoundHandler())
for _, path := range []string{"/", "/index.html", "/app-config.js", "/users"} {
response := httptest.NewRecorder()
handler.ServeHTTP(response, httptest.NewRequest(http.MethodGet, path, nil))
if got := response.Header().Get("Cache-Control"); got != "no-store" {
t.Fatalf("%s Cache-Control=%q, want no-store", path, got)
}
}
}
func TestHandlerCachesHashedAssetsImmutably(t *testing.T) {
dir := t.TempDir()
assets := filepath.Join(dir, "assets")
if err := os.Mkdir(assets, 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(assets, "app-1234.js"), []byte("app"), 0o600); err != nil {
t.Fatal(err)
}
response := httptest.NewRecorder()
Handler(dir, http.NotFoundHandler()).ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/assets/app-1234.js", nil))
if got := response.Header().Get("Cache-Control"); got != "public, max-age=31536000, immutable" {
t.Fatalf("asset Cache-Control=%q", got)
}
}