Extract iputil package

This commit is contained in:
Martin Polden
2018-02-10 14:35:12 +01:00
parent 35061bfe83
commit 8112536125
8 changed files with 217 additions and 254 deletions

23
iputil/iputil_test.go Normal file
View File

@ -0,0 +1,23 @@
package iputil
import (
"math/big"
"net"
"testing"
)
func TestToDecimal(t *testing.T) {
var tests = []struct {
in string
out *big.Int
}{
{"127.0.0.1", big.NewInt(2130706433)},
{"::1", big.NewInt(1)},
}
for _, tt := range tests {
i := ToDecimal(net.ParseIP(tt.in))
if i.Cmp(tt.out) != 0 {
t.Errorf("Expected %d, got %d for IP %s", tt.out, i, tt.in)
}
}
}