echoip/iputil/iputil_test.go

28 lines
490 B
Go
Raw Permalink Normal View History

2018-02-10 14:35:12 +01:00
package iputil
import (
"math/big"
2018-02-10 14:35:12 +01:00
"net"
"testing"
)
func TestToDecimal(t *testing.T) {
var msb = new(big.Int)
msb, _ = msb.SetString("80000000000000000000000000000000", 16)
2018-02-10 14:35:12 +01:00
var tests = []struct {
in string
out *big.Int
2018-02-10 14:35:12 +01:00
}{
{"127.0.0.1", big.NewInt(2130706433)},
{"::1", big.NewInt(1)},
{"8000::", msb},
2018-02-10 14:35:12 +01:00
}
for _, tt := range tests {
i := ToDecimal(net.ParseIP(tt.in))
if tt.out.Cmp(i) != 0 {
2018-02-10 14:35:12 +01:00
t.Errorf("Expected %d, got %d for IP %s", tt.out, i, tt.in)
}
}
}