refactor: move V1 code into v1/ subdirectory

- git mv cmd/ internal/ pkg/ test/ go.mod go.sum Makefile build.sh docs/ v1/
- Create v1/README.md with V1 documentation
- Update root README for V1 + V2 structure
- V1 still builds (cd v1 && go build ./cmd/hostkeeper) and 105 tests pass
- Root is now clean for V2 development
This commit is contained in:
swanadiva
2026-07-07 11:56:27 +07:00
parent 8ebdebedc8
commit 847989df75
68 changed files with 58 additions and 116 deletions
+119
View File
@@ -0,0 +1,119 @@
package tui
import (
"testing"
)
func TestTUIInitialization(t *testing.T) {
ui := New()
if ui == nil {
t.Fatal("Failed to initialize TUI")
}
if ui.tabs == nil {
t.Fatal("expected tabs manager to be initialized")
}
if ui.tabs.Len() != 1 {
t.Errorf("expected 1 tab, got %d", ui.tabs.Len())
}
if ui.Quit {
t.Error("expected Quit to be false")
}
// Should have a HostListTab by default
ht := FindHostListTab(ui.tabs.tabs)
if ht == nil {
t.Error("expected HostListTab to be the initial tab")
}
}
func TestTUILoadHosts(t *testing.T) {
ui := New()
if ui == nil {
t.Fatal("Failed to initialize TUI")
}
ui.LoadHosts(nil)
if ui.Hosts != nil {
t.Error("expected Hosts to be nil")
}
// Should still have a valid tab manager
if ui.tabs == nil {
t.Fatal("expected tabs manager to be valid")
}
}
func TestTabManagerBasic(t *testing.T) {
tm := NewTabManager(NewHostListTab())
if tm.Len() != 1 {
t.Errorf("expected 1 tab, got %d", tm.Len())
}
if tm.Active() == nil {
t.Fatal("expected active tab")
}
if tm.Active().Name() != "Hosts" {
t.Errorf("expected 'Hosts', got '%s'", tm.Active().Name())
}
}
func TestTabManagerNavigation(t *testing.T) {
tm := NewTabManager(NewHostListTab())
// Add a second tab
second := NewHostListTab()
tm.Add(second)
if tm.Len() != 2 {
t.Errorf("expected 2 tabs, got %d", tm.Len())
}
// Active should now be the last added tab
if tm.active != 1 {
t.Errorf("expected active index 1, got %d", tm.active)
}
// Previous
tm.Prev()
if tm.active != 0 {
t.Errorf("expected active index 0 after Prev, got %d", tm.active)
}
// Next
tm.Next()
if tm.active != 1 {
t.Errorf("expected active index 1 after Next, got %d", tm.active)
}
}
func TestTabManagerClose(t *testing.T) {
tm := NewTabManager(NewHostListTab())
second := NewHostListTab()
tm.Add(second)
tm.Add(NewHostListTab())
// Close active (last tab)
closed := tm.CloseActive()
if closed == nil {
t.Error("expected closed tab to be returned")
}
if tm.Len() != 2 {
t.Errorf("expected 2 tabs after close, got %d", tm.Len())
}
// Close all tabs except last
tm.Close(0)
if tm.Len() != 1 {
t.Errorf("expected 1 tab after close, got %d", tm.Len())
}
// Should not close the last tab via CloseActive (returns nil)
result := tm.CloseActive()
if result != nil {
t.Error("expected nil when trying to close the last tab")
}
}