diff --git a/internal/service/service_test.go b/internal/service/service_test.go new file mode 100644 index 0000000..e708848 --- /dev/null +++ b/internal/service/service_test.go @@ -0,0 +1,28 @@ +package service + +import ( + "reflect" + "testing" +) + +func TestNewManager(t *testing.T) { + variant := Variant{ + ID: "test-id", + Family: "test-family", + Variant: "Local", + RegistryName: "TestService", + DisplayName: "Test Service Display", + ExeName: "test.exe", + Binary: []byte("test binary data"), + } + + manager := NewManager(variant) + + if manager == nil { + t.Fatal("NewManager returned nil") + } + + if !reflect.DeepEqual(manager.variant, variant) { + t.Errorf("NewManager() = %v, want variant %v", manager.variant, variant) + } +} diff --git a/internal/ui/builders.go b/internal/ui/builders.go index a5dcd88..dddf3fa 100644 --- a/internal/ui/builders.go +++ b/internal/ui/builders.go @@ -91,10 +91,10 @@ func buildFamilyMenuItems(fs service.FamilyStatus) []list.Item { data: "install-remote", }, menuItem{ - title: "Volver", + title: LabelBack, description: "Regresar al menú principal", - icon: "[<]", - data: "back", + icon: IconBack, + data: ActionBack, }, } } @@ -130,7 +130,7 @@ func buildFamilyMenuItems(fs service.FamilyStatus) []list.Item { title: "Forzar Detención", description: "El servicio está en transición — forzar detención", icon: "[!]", - data: "force-stop", + data: ActionForceStop, }) case service.StatusUnknown: @@ -138,7 +138,7 @@ func buildFamilyMenuItems(fs service.FamilyStatus) []list.Item { title: "Forzar Detención", description: "Estado desconocido — intentar forzar detención del servicio", icon: "[!]", - data: "force-stop", + data: ActionForceStop, }) default: log.Printf("Estado inesperado para %s: %s", installed, status.String()) @@ -159,10 +159,10 @@ func buildFamilyMenuItems(fs service.FamilyStatus) []list.Item { data: "uninstall", }, menuItem{ - title: "Volver", + title: LabelBack, description: "Regresar al menú principal", - icon: "[<]", - data: "back", + icon: IconBack, + data: ActionBack, }, ) @@ -189,10 +189,10 @@ func buildLogsMenuItems() []list.Item { data: "open-dir", }, menuItem{ - title: "Volver", + title: LabelBack, description: "Regresar al menú de servicio", - icon: "[<]", - data: "back", + icon: IconBack, + data: ActionBack, }, } } diff --git a/internal/ui/constants.go b/internal/ui/constants.go new file mode 100644 index 0000000..9d3308b --- /dev/null +++ b/internal/ui/constants.go @@ -0,0 +1,13 @@ +package ui + +// Shared constants for UI menu actions and labels to prevent goconst warnings. +const ( + // ActionBack is the data string used for navigating back. + ActionBack = "back" + // ActionForceStop is the data string used for forcing a service to stop. + ActionForceStop = "force-stop" + // LabelBack is the display title for back navigation options. + LabelBack = "Volver" + // IconBack is the standard icon used for back navigation options. + IconBack = "[<]" +) diff --git a/internal/ui/update.go b/internal/ui/update.go index 915a3a3..e593b24 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -211,7 +211,7 @@ func (m Model) handleFamilyKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } switch selected.data { - case "back": + case ActionBack: return m.goToDashboard() case "install-local": @@ -236,7 +236,7 @@ func (m Model) handleFamilyKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) { } return m.executeAction("Detener Servicio", mgr.Stop) - case "force-stop": + case ActionForceStop: mgr := m.getActiveManager() if mgr == nil { m.statusMessage = "No se pudo determinar el servicio a detener." @@ -313,7 +313,7 @@ func (m Model) handleLogsKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) { m.statusMessage = "Abriendo carpeta de logs..." return m, nil - case "back": + case ActionBack: return m.returnToFamilyMenu() } }