github.com/prebid/prebid-server/v2@v2.18.0/util/iputil/parse_test.go (about)

     1  package iputil
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestParseIP(t *testing.T) {
    11  	testCases := []struct {
    12  		input       string
    13  		expectedVer IPVersion
    14  		expectedIP  net.IP
    15  	}{
    16  		{"", IPvUnknown, nil},
    17  		{"1.1.1.1", IPv4, net.IPv4(1, 1, 1, 1)},
    18  		{"-1.-1.-1.-1", IPvUnknown, nil},
    19  		{"256.256.256.256", IPvUnknown, nil},
    20  		{"::ffff:1.1.1.1", IPv6, net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 1, 1, 1, 1}},
    21  		{"0101::", IPv6, net.IP{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
    22  		{"zzzz::", IPvUnknown, nil},
    23  	}
    24  
    25  	for _, test := range testCases {
    26  		ip, ver := ParseIP(test.input)
    27  		assert.Equal(t, test.expectedVer, ver)
    28  		assert.Equal(t, test.expectedIP, ip)
    29  	}
    30  }