mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
Christian Ditaputratama
c3f837e122
This commit add IsIPv6Only function inside `internal/ip` package and moving `geo` package from `internal/geo` to `internal/ip/geo`. Although it increases server resource usage, checking hostname to IP is required every time the prober sends a report so that the `ipv6_only` record in the database is not up-to-date. Previously, this feature did not exist.
46 lines
762 B
Go
46 lines
762 B
Go
package ip
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
// Single test: go test ./internal/ip -bench TestIsIPv6Only -benchmem -run=^$ -v
|
|
func TestIsIPv6Only(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
ips []net.IP
|
|
want bool
|
|
}{
|
|
{
|
|
name: "IPv4",
|
|
ips: []net.IP{
|
|
net.ParseIP("1.1.1.1"),
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "IPv6",
|
|
ips: []net.IP{
|
|
net.ParseIP("2606:4700::6810:85e5"),
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "IPv6 and IPv4",
|
|
ips: []net.IP{
|
|
net.ParseIP("1.1.1.1"),
|
|
net.ParseIP("2606:4700::6810:84e5"),
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := IsIPv6Only(tt.ips); got != tt.want {
|
|
t.Errorf("IsIPv6Only() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|