From d242ceac46d1fd7a17de8785c22ee59344ff9a6c Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 21 Oct 2022 14:07:46 +0200 Subject: [PATCH] Make hostname dns safe, allow string in ping command Signed-off-by: Kristoffer Dalby --- integration/general_test.go | 2 +- integration/tailscale.go | 2 +- integration/tsic/tsic.go | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integration/general_test.go b/integration/general_test.go index 50ce89c4..e4765f71 100644 --- a/integration/general_test.go +++ b/integration/general_test.go @@ -58,7 +58,7 @@ func TestPingAll(t *testing.T) { for _, client := range allClients { for _, ip := range allIps { - err := client.Ping(ip) + err := client.Ping(ip.String()) if err != nil { t.Errorf("failed to ping %s from %s: %s", ip, client.Hostname(), err) } else { diff --git a/integration/tailscale.go b/integration/tailscale.go index b163c290..4d21798f 100644 --- a/integration/tailscale.go +++ b/integration/tailscale.go @@ -14,5 +14,5 @@ type TailscaleClient interface { IPs() ([]netip.Addr, error) Status() (*ipnstate.Status, error) WaitForPeers(expected int) error - Ping(ip netip.Addr) error + Ping(hostnameOrIP string) error } diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index f21dccae..1cdc3711 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -46,7 +46,7 @@ func New( return nil, err } - hostname := fmt.Sprintf("ts-%s-%s", version, hash) + hostname := fmt.Sprintf("ts-%s-%s", strings.ReplaceAll(version, ".", "-"), hash) // TODO(kradalby): figure out why we need to "refresh" the network here. // network, err = dockertestutil.GetFirstOrCreateNetwork(pool, network.Network.Name) @@ -220,14 +220,14 @@ func (t *TailscaleInContainer) WaitForPeers(expected int) error { } // TODO(kradalby): Make multiping, go routine magic. -func (t *TailscaleInContainer) Ping(ip netip.Addr) error { +func (t *TailscaleInContainer) Ping(hostnameOrIP string) error { return t.pool.Retry(func() error { command := []string{ "tailscale", "ping", "--timeout=1s", "--c=10", "--until-direct=true", - ip.String(), + hostnameOrIP, } result, _, err := dockertestutil.ExecuteCommand( @@ -238,8 +238,8 @@ func (t *TailscaleInContainer) Ping(ip netip.Addr) error { if err != nil { log.Printf( "failed to run ping command from %s to %s, err: %s", - t.hostname, - ip.String(), + t.Hostname(), + hostnameOrIP, err, )