ERP/main_test.go

43 lines
1.2 KiB
Go
Raw Permalink Normal View History

2026-02-06 19:14:13 +01:00
package main_test
import (
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestResources_Favicon(t *testing.T) {
// Create resources directory and dummy favicon if not exists
if _, err := os.Stat("resources"); os.IsNotExist(err) {
os.Mkdir("resources", 0755)
}
if _, err := os.Stat("resources/favicon.png"); os.IsNotExist(err) {
os.WriteFile("resources/favicon.png", []byte("dummy"), 0644)
defer os.Remove("resources/favicon.png")
}
// Setup handler exactly as in main.go
mux := http.NewServeMux()
mux.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources"))))
mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "resources/favicon.png")
})
// Test request for resources path
req := httptest.NewRequest("GET", "/resources/favicon.png", nil)
w := httptest.NewRecorder()
mux.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("GET /resources/favicon.png failed: %d", w.Code)
}
// Test request for favicon.ico
reqIco := httptest.NewRequest("GET", "/favicon.ico", nil)
wIco := httptest.NewRecorder()
mux.ServeHTTP(wIco, reqIco)
if wIco.Code != http.StatusOK {
t.Errorf("GET /favicon.ico failed: %d", wIco.Code)
}
}