chore(all): replace net.IP with netip.Addr

This commit is contained in:
Quentin McGaw
2023-05-20 19:58:18 +00:00
parent 00ee6ff9a7
commit 0a29337c3b
91 changed files with 525 additions and 590 deletions

View File

@@ -2,7 +2,7 @@ package extract
import (
"errors"
"net"
"net/netip"
"testing"
"github.com/qdm12/gluetun/internal/constants"
@@ -22,7 +22,7 @@ func Test_extractDataFromLines(t *testing.T) {
"success": {
lines: []string{"bla bla", "proto tcp", "remote 1.2.3.4 1194 tcp", "dev tun6"},
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 1194,
Protocol: constants.TCP,
},
@@ -34,7 +34,7 @@ func Test_extractDataFromLines(t *testing.T) {
"only use first values found": {
lines: []string{"proto udp", "proto tcp", "remote 1.2.3.4 443 tcp", "remote 5.2.3.4 1194 udp"},
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 443,
Protocol: constants.UDP,
},
@@ -49,7 +49,7 @@ func Test_extractDataFromLines(t *testing.T) {
"default TCP port": {
lines: []string{"remote 1.2.3.4", "proto tcp"},
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 443,
Protocol: constants.TCP,
},
@@ -57,7 +57,7 @@ func Test_extractDataFromLines(t *testing.T) {
"default UDP port": {
lines: []string{"remote 1.2.3.4", "proto udp"},
connection: models.Connection{
IP: net.IPv4(1, 2, 3, 4),
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 1194,
Protocol: constants.UDP,
},
@@ -88,7 +88,7 @@ func Test_extractDataFromLine(t *testing.T) {
testCases := map[string]struct {
line string
ip net.IP
ip netip.Addr
port uint16
protocol string
isErr error
@@ -110,7 +110,7 @@ func Test_extractDataFromLine(t *testing.T) {
},
"extract remote success": {
line: "remote 1.2.3.4 1194 udp",
ip: net.IPv4(1, 2, 3, 4),
ip: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
port: 1194,
protocol: constants.UDP,
},
@@ -186,7 +186,7 @@ func Test_extractRemote(t *testing.T) {
testCases := map[string]struct {
line string
ip net.IP
ip netip.Addr
port uint16
protocol string
err error
@@ -205,7 +205,7 @@ func Test_extractRemote(t *testing.T) {
},
"only IP host": {
line: "remote 1.2.3.4",
ip: net.IPv4(1, 2, 3, 4),
ip: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
},
"port not an integer": {
line: "remote 1.2.3.4 bad",
@@ -225,7 +225,7 @@ func Test_extractRemote(t *testing.T) {
},
"IP host and port": {
line: "remote 1.2.3.4 8000",
ip: net.IPv4(1, 2, 3, 4),
ip: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
port: 8000,
},
"invalid protocol": {
@@ -234,7 +234,7 @@ func Test_extractRemote(t *testing.T) {
},
"IP host and port and protocol": {
line: "remote 1.2.3.4 8000 udp",
ip: net.IPv4(1, 2, 3, 4),
ip: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
port: 8000,
protocol: constants.UDP,
},