tstest/integration: change return type of AwaitIP from string to netaddr.IP

Signed-off-by: Simeng He <simeng@tailscale.com>
This commit is contained in:
Simeng He 2021-07-09 11:51:30 -04:00 committed by Brad Fitzpatrick
parent 46896a9311
commit 3d049a9d71

View File

@ -23,12 +23,14 @@
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
"go4.org/mem" "go4.org/mem"
"inet.af/netaddr"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/safesocket" "tailscale.com/safesocket"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
@ -528,22 +530,40 @@ func (n *testNode) AwaitListening(t testing.TB) {
} }
} }
func (n *testNode) AwaitIP(t testing.TB) (ips string) { func (n *testNode) AwaitIPs(t testing.TB) []netaddr.IP {
t.Helper() t.Helper()
var addrs []netaddr.IP
if err := tstest.WaitFor(20*time.Second, func() error { if err := tstest.WaitFor(20*time.Second, func() error {
out, err := n.Tailscale("ip").Output() out, err := n.Tailscale("ip").Output()
if err != nil { if err != nil {
return err return err
} }
ips = string(out) ips := string(out)
ipslice := strings.Fields(ips)
addrs = make([]netaddr.IP, len(ipslice))
for i, ip := range ipslice {
netIP, err := netaddr.ParseIP(ip)
if err != nil {
t.Fatal(err)
}
addrs[i] = netIP
}
return nil return nil
}); err != nil { }); err != nil {
t.Fatalf("awaiting an IP address: %v", err) t.Fatalf("awaiting an IP address: %v", err)
} }
if ips == "" { if len(addrs) == 0 {
t.Fatalf("returned IP address was blank") t.Fatalf("returned IP address was blank")
} }
return ips return addrs
}
// AwaitIP returns the IP address of n.
func (n *testNode) AwaitIP(t testing.TB) netaddr.IP {
t.Helper()
ips := n.AwaitIPs(t)
return ips[0]
} }
func (n *testNode) AwaitRunning(t testing.TB) { func (n *testNode) AwaitRunning(t testing.TB) {