1 // Copyright 2017, Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
13 "github.com/google/gopacket"
16 func TestNewIPEndpoint(t *testing.T) {
19 endpointType gopacket.EndpointType
21 {net.ParseIP("192.168.0.1").To4(), EndpointIPv4},
22 {net.ParseIP("192.168.0.1").To16(), EndpointIPv4},
23 {net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), EndpointIPv6},
26 for _, c := range cases {
27 endpoint := NewIPEndpoint(c.ip)
28 if endpoint == gopacket.InvalidEndpoint {
29 t.Errorf("Failed to create an IP endpoint for %s (%d-bytes)",
32 if endpoint.EndpointType() != c.endpointType {
33 t.Errorf("Wrong endpoint type created for %s (%d-bytes): expected %s, got %s",
34 c.ip, len(c.ip), c.endpointType, endpoint.EndpointType())