package web import ( "strings" "testing" "gitgud.io/mike/mpv-manager/pkg/config" "gitgud.io/mike/mpv-manager/pkg/installer" "gitgud.io/mike/mpv-manager/pkg/platform" ) // TestLogsAndConfigTemplatesRender executes the "logs" and "config" page // templates with the data types used by their handlers, failing if Go // template evaluation errors leak into the rendered HTML. func TestLogsAndConfigTemplatesRender(t *testing.T) { p := platform.Detect() cfg, _ := config.Load() releaseInfo := installer.ReleaseInfo{} inst := installer.NewInstaller(releaseInfo, config.GetInstallPath()) server := NewServer(p, cfg, inst, &releaseInfo) t.Run("logs", func(t *testing.T) { var sb strings.Builder err := server.templates.ExecuteTemplate(&sb, "logs", logsPageData{ DashboardData: DashboardData{Title: "Logs"}, LogFilePath: "/tmp/mpv-manager.log", DebugMode: true, VerboseMode: false, }) if err != nil { t.Fatalf("logs template execution failed: %v", err) } out := sb.String() if strings.Contains(out, "can't evaluate") { t.Errorf("template evaluation error leaked into output: %s", out) } if !strings.Contains(out, "/tmp/mpv-manager.log") { t.Errorf("expected log file path in output") } if !strings.Contains(out, "Debug") { t.Errorf("expected Debug log level in output") } }) t.Run("config", func(t *testing.T) { var sb strings.Builder err := server.templates.ExecuteTemplate(&sb, "config", configPageData{ DashboardData: DashboardData{ Title: "Config", ConfigBackups: []ConfigBackup{{Filename: "b.conf", CreatedDate: "2026-01-02 00:00:00", FilePath: "/tmp/b.conf"}}, Config: &ConfigSettings{ConfigFile: "/tmp/mpv.conf"}, }, ConfigBackupDir: "/tmp/conf_backups", BackupList: buildConfigBackupsListData( []ConfigBackup{{Filename: "b.conf", CreatedDate: "2026-01-02 00:00:00", FilePath: "/tmp/b.conf"}}, "", 0, ), }) if err != nil { t.Fatalf("config template execution failed: %v", err) } out := sb.String() if strings.Contains(out, "can't evaluate") { t.Errorf("template evaluation error leaked into output: %s", out) } if !strings.Contains(out, "/tmp/mpv.conf") || !strings.Contains(out, "/tmp/conf_backups") { t.Errorf("expected real config and backup paths in output") } if !strings.Contains(out, "b.conf") { t.Errorf("expected backup list partial content in output") } }) }