mirror of
https://github.com/hanzoai/oxy.git
synced 2026-09-30 23:42:31 +00:00
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
package forward
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_ipv6fix(t *testing.T) {
|
|
testCases := []struct {
|
|
desc string
|
|
clientIP string
|
|
expected string
|
|
}{
|
|
{
|
|
desc: "empty",
|
|
clientIP: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
desc: "ipv4 localhost",
|
|
clientIP: "127.0.0.1",
|
|
expected: "127.0.0.1",
|
|
},
|
|
{
|
|
desc: "ipv4",
|
|
clientIP: "10.13.14.15",
|
|
expected: "10.13.14.15",
|
|
},
|
|
{
|
|
desc: "ipv6 zone",
|
|
clientIP: `fe80::d806:a55d:eb1b:49cc%vEthernet (vmxnet3 Ethernet Adapter - Virtual Switch)`,
|
|
expected: "fe80::d806:a55d:eb1b:49cc",
|
|
},
|
|
{
|
|
desc: "ipv6 medium",
|
|
clientIP: `fe80::1`,
|
|
expected: "fe80::1",
|
|
},
|
|
{
|
|
desc: "ipv6 small",
|
|
clientIP: `2000::`,
|
|
expected: "2000::",
|
|
},
|
|
{
|
|
desc: "ipv6",
|
|
clientIP: `2001:3452:4952:2837::`,
|
|
expected: "2001:3452:4952:2837::",
|
|
},
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
actual := ipv6fix(test.clientIP)
|
|
assert.Equal(t, test.expected, actual)
|
|
})
|
|
}
|
|
}
|