mirror of
https://github.com/qdm12/gluetun.git
synced 2025-12-11 04:38:54 -06:00
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package routing
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_netIPToNetipAddress(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
testCases := map[string]struct {
|
|
ip net.IP
|
|
address netip.Addr
|
|
panicMessage string
|
|
}{
|
|
"nil ip": {
|
|
panicMessage: "converting net.IP(nil) to netip.Addr failed",
|
|
},
|
|
"IPv4": {
|
|
ip: net.IPv4(1, 2, 3, 4),
|
|
address: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
|
|
},
|
|
"IPv6": {
|
|
ip: net.IPv6zero,
|
|
address: netip.AddrFrom16([16]byte{}),
|
|
},
|
|
"IPv4 prefixed with 0xffff": {
|
|
ip: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 1, 2, 3, 4},
|
|
address: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
|
|
},
|
|
}
|
|
|
|
for name, testCase := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if testCase.panicMessage != "" {
|
|
assert.PanicsWithValue(t, testCase.panicMessage, func() {
|
|
netIPToNetipAddress(testCase.ip)
|
|
})
|
|
return
|
|
}
|
|
|
|
address := netIPToNetipAddress(testCase.ip)
|
|
assert.Equal(t, testCase.address, address)
|
|
})
|
|
}
|
|
}
|