package app import "testing" func TestVisibleSessionTreeScopesToFocusedRoot(t *testing.T) { root1 := testChild("c1", "root1", "", StatusRunning) child1 := testChild("c2", "child1", "c1", StatusRunning) root2 := testChild("c3", "root2", "", StatusRunning) child2 := testChild("c4", "child2", "c3", StatusRunning) got := visibleSessionTree([]*Child{root1, child1, root2, child2}, "c4") if len(got) != 2 || got[0].ID != "c3" || got[1].ID != "c4" { t.Fatalf("visible tree = %v, want root2 + child2", childIDs(got)) } } func TestVisibleSessionTreeOmitsExited(t *testing.T) { root := testChild("c1", "root", "", StatusRunning) exitedRoot := testChild("c2", "dead-root", "", StatusExited) runningChild := testChild("c3", "child", "c1", StatusRunning) exitedChild := testChild("c4", "dead-child", "c1", StatusExited) got := visibleSessionTree([]*Child{root, exitedRoot, runningChild, exitedChild}, "c1") if len(got) != 2 || got[0].ID != "c1" || got[1].ID != "c3" { t.Fatalf("visible tree = %v, want running root + running child", childIDs(got)) } } func testChild(id, name, parent string, status ChildStatus) *Child { c := &Child{ID: id, Name: name, ParentID: parent} c.status.Store(&status) return c } func childIDs(cs []*Child) []string { ids := make([]string, 0, len(cs)) for _, c := range cs { ids = append(ids, c.ID) } return ids }