From d5cc5b2bc8f07b1456560936f164a5faca02c842 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 2 Sep 2022 09:22:34 +0200 Subject: [PATCH] Move integration tests to net/netip --- integration_common_test.go | 12 ++++++------ integration_general_test.go | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/integration_common_test.go b/integration_common_test.go index 027eeff3..fb5abb13 100644 --- a/integration_common_test.go +++ b/integration_common_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "net/netip" "os" "strconv" "strings" @@ -15,7 +16,6 @@ import ( v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" - "inet.af/netaddr" ) const ( @@ -26,8 +26,8 @@ const ( var ( errEnvVarEmpty = errors.New("getenv: environment variable empty") - IpPrefix4 = netaddr.MustParseIPPrefix("100.64.0.0/10") - IpPrefix6 = netaddr.MustParseIPPrefix("fd7a:115c:a1e0::/48") + IpPrefix4 = netip.MustParsePrefix("100.64.0.0/10") + IpPrefix6 = netip.MustParsePrefix("fd7a:115c:a1e0::/48") tailscaleVersions = []string{ // "head", @@ -195,8 +195,8 @@ func getDockerBuildOptions(version string) *dockertest.BuildOptions { func getIPs( tailscales map[string]dockertest.Resource, -) (map[string][]netaddr.IP, error) { - ips := make(map[string][]netaddr.IP) +) (map[string][]netip.Addr, error) { + ips := make(map[string][]netip.Addr) for hostname, tailscale := range tailscales { command := []string{"tailscale", "ip"} @@ -214,7 +214,7 @@ func getIPs( if len(address) < 1 { continue } - ip, err := netaddr.ParseIP(address) + ip, err := netip.ParseAddr(address) if err != nil { return nil, err } diff --git a/integration_general_test.go b/integration_general_test.go index 9f2ca3ea..66652d73 100644 --- a/integration_general_test.go +++ b/integration_general_test.go @@ -10,6 +10,7 @@ import ( "fmt" "log" "net/http" + "net/netip" "os" "path" "strings" @@ -22,7 +23,6 @@ import ( "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "inet.af/netaddr" "tailscale.com/client/tailscale/apitype" "tailscale.com/ipn/ipnstate" ) @@ -477,8 +477,8 @@ func (s *IntegrationTestSuite) TestGetIpAddresses() { // } // } -func getIPsfromIPNstate(status ipnstate.Status) []netaddr.IP { - ips := make([]netaddr.IP, 0) +func getIPsfromIPNstate(status ipnstate.Status) []netip.Addr { + ips := make([]netip.Addr, 0) for _, peer := range status.Peer { ips = append(ips, peer.TailscaleIPs...) @@ -563,14 +563,14 @@ func (s *IntegrationTestSuite) TestTailDrop() { continue } - var ip4 netaddr.IP + var ip4 netip.Addr for _, ip := range ips[peername] { if ip.Is4() { ip4 = ip break } } - if ip4.IsZero() { + if ip4.IsUnspecified() { panic("no ipv4 address found") } @@ -748,8 +748,8 @@ func (s *IntegrationTestSuite) TestMagicDNS() { func getAPIURLs( tailscales map[string]dockertest.Resource, -) (map[netaddr.IP]string, error) { - fts := make(map[netaddr.IP]string) +) (map[netip.Addr]string, error) { + fts := make(map[netip.Addr]string) for _, tailscale := range tailscales { command := []string{ "curl", @@ -773,11 +773,11 @@ func getAPIURLs( for _, ft := range pft { n := ft.Node for _, a := range n.Addresses { // just add all the addresses - if _, ok := fts[a.IP()]; !ok { + if _, ok := fts[a.Addr()]; !ok { if ft.PeerAPIURL == "" { return nil, errors.New("api url is empty") } - fts[a.IP()] = ft.PeerAPIURL + fts[a.Addr()] = ft.PeerAPIURL } } }