Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tools/agent_tui/ui/rendezvous_ip_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
RENDEZVOUS_CONFIGURE_NETWORK_BUTTON = "<Configure Network>"
)

var getInterfaceAddrs = net.InterfaceAddrs

func (u *UI) createSelectHostIPPage() {
u.selectIPList = tview.NewList()
u.refreshSelectIPList()
Expand Down Expand Up @@ -56,7 +58,7 @@ func (u *UI) createSelectHostIPPage() {
}

func (u *UI) hostIPAddresses() []string {
addrs, err := net.InterfaceAddrs()
addrs, err := getInterfaceAddrs()
if err != nil {
u.logger.Errorf("Could not fetch host IPs: %v", err)
}
Expand Down
31 changes: 31 additions & 0 deletions tools/agent_tui/ui/rendezvous_ip_select_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
package ui

import (
"net"
"testing"

"github.com/gdamore/tcell/v2"
"github.com/openshift/agent-installer-utils/tools/agent_tui/checks"
"github.com/rivo/tview"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestSetFocusToSelectIPRefreshesHostIPList(t *testing.T) {
originalGetInterfaceAddrs := getInterfaceAddrs
t.Cleanup(func() {
getInterfaceAddrs = originalGetInterfaceAddrs
})

addresses := []net.Addr{&net.IPNet{IP: net.ParseIP("192.0.2.1")}}
getInterfaceAddrs = func() ([]net.Addr, error) {
return addresses, nil
}

ui := NewUI(tview.NewApplication(), checks.Config{}, logrus.New(), "")
assert.Equal(t, []string{"192.0.2.1", EMPTY_OPTION, BACK_BUTTON}, selectIPListItems(ui.selectIPList))

addresses = []net.Addr{&net.IPNet{IP: net.ParseIP("192.0.2.2")}}
ui.setFocusToSelectIP()

assert.Equal(t, []string{"192.0.2.2", EMPTY_OPTION, BACK_BUTTON}, selectIPListItems(ui.selectIPList))
}

// Test the InputCapture works correctly
func TestSelectIPListNavigation(t *testing.T) {
list := tview.NewList()
Expand Down Expand Up @@ -82,3 +105,11 @@ func applyKeyToList(list *tview.List, key tcell.Key, numKeyPresses int) {
list.InputHandler()(tcell.NewEventKey(key, 0, tcell.ModNone), func(p tview.Primitive) {})
}
}

func selectIPListItems(list *tview.List) []string {
items := make([]string, list.GetItemCount())
for i := range items {
items[i], _ = list.GetItemText(i)
}
return items
}
1 change: 1 addition & 0 deletions tools/agent_tui/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (u *UI) setFocusToRendezvousIP() {

func (u *UI) setFocusToSelectIP() {
u.setIsRendezousIPFormActive(true)
u.refreshSelectIPList()
u.pages.SwitchToPage(PAGE_SET_NODE_AS_RENDEZVOUS)

u.app.SetFocus(u.selectIPList)
Expand Down