package routes import ( "fmt" "net/http" "net/http/httptest" "os" "path/filepath" "regexp" "strings" "testing" "gitview/internal/config" ) // Verify configured branding renders consistently and resolves to the served asset. func TestConfiguredBranding(t *testing.T) { c, _ := testWorkspace(t) static := t.TempDir() if err := os.MkdirAll(filepath.Join(static, "branding"), 0755); err != nil { t.Fatal(err) } const svg = `` for _, name := range []string{"favicon.svg", "branding/owner mark.svg"} { if err := os.WriteFile(filepath.Join(static, name), []byte(svg), 0644); err != nil { t.Fatal(err) } } favicon := regexp.MustCompile(``) if !found { t.Fatalf("%s: missing topbar", page.url) } topbar, _, _ := strings.Cut(header, "") if !strings.Contains(topbar, `class="brand-name">arnaucube`) || strings.Contains(topbar, "browser-only-title") || strings.Contains(topbar, "top-context") { t.Errorf("%s: topbar does not use only the configured username", page.url) } if !strings.Contains(body, "browser-only-title") { t.Errorf("%s: browser title was lost", page.url) } } w := httptest.NewRecorder() handler.ServeHTTP(w, httptest.NewRequest("GET", tt.asset, nil)) if w.Code != http.StatusOK || w.Body.String() != svg { t.Fatalf("logo request: status %d, body %q", w.Code, w.Body.String()) } if got := w.Header().Get("Content-Type"); !strings.HasPrefix(got, "image/svg+xml") { t.Errorf("logo content type: %q", got) } loaded.Repo.ScanPath = filepath.Join(t.TempDir(), "missing") w = httptest.NewRecorder() handler.ServeHTTP(w, httptest.NewRequest("GET", "/", nil)) if w.Code != 500 || !strings.Contains(w.Body.String(), tt.asset) { t.Errorf("server error page lost configured branding: status %d", w.Code) } }) } }