Revision eeb3e8cd5e0d6e269575b51e2b8c462503c12c0b authored by Tom Hadlaw on 20 July 2024, 19:48:55 UTC, committed by Tom Hadlaw on 20 July 2024, 19:48:55 UTC
Signed-off-by: Tom Hadlaw <tom.hadlaw@isovalent.com>
1 parent acc80d2
Raw File
ipv6_test.go
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package types

import (
	"net"
	"net/netip"
	"testing"

	"github.com/stretchr/testify/require"
)

var testIPv6Address IPv6 = [16]byte{240, 13, 0, 0, 0, 0, 0, 0, 172, 16, 0, 20, 0, 0, 0, 1}

func TestIPv6(t *testing.T) {
	var expectedAddress net.IP = []byte{240, 13, 0, 0, 0, 0, 0, 0, 172, 16, 0, 20, 0, 0, 0, 1}
	result := testIPv6Address.IP()

	require.EqualValues(t, expectedAddress, result)
}

func TestAddrV6(t *testing.T) {
	expectedAddress := netip.AddrFrom16(testIPv6Address)
	result := testIPv6Address.Addr()

	require.EqualValues(t, expectedAddress, result)
}

func TestStringV6(t *testing.T) {
	expectedStr := "f00d::ac10:14:0:1"
	result := testIPv6Address.String()

	require.Equal(t, expectedStr, result)
}
back to top