mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
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:
parent
46896a9311
commit
3d049a9d71
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user