From 1672322fc10d0304080e1e3e866d31c26bb71557 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Fri, 7 Oct 2022 21:22:22 -0500 Subject: [PATCH] test ContainsIP utility --- util/util_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/util/util_test.go b/util/util_test.go index 807d5997..a435c066 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -1,10 +1,12 @@ package util import ( - "github.com/stretchr/testify/require" + "net/netip" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/require" ) func TestRandomString(t *testing.T) { @@ -42,6 +44,13 @@ func TestContains(t *testing.T) { require.False(t, Contains(s, 3)) } +func TestContainsIP(t *testing.T) { + require.True(t, ContainsIP([]netip.Prefix{netip.MustParsePrefix("fd00::/8"), netip.MustParsePrefix("1.1.0.0/16")}, netip.MustParseAddr("1.1.1.1"))) + require.True(t, ContainsIP([]netip.Prefix{netip.MustParsePrefix("fd00::/8"), netip.MustParsePrefix("1.1.0.0/16")}, netip.MustParseAddr("fd12:1234:5678::9876"))) + require.False(t, ContainsIP([]netip.Prefix{netip.MustParsePrefix("fd00::/8"), netip.MustParsePrefix("1.1.0.0/16")}, netip.MustParseAddr("1.2.0.1"))) + require.False(t, ContainsIP([]netip.Prefix{netip.MustParsePrefix("fd00::/8"), netip.MustParsePrefix("1.1.0.0/16")}, netip.MustParseAddr("fc00::1"))) +} + func TestSplitNoEmpty(t *testing.T) { require.Equal(t, []string{}, SplitNoEmpty("", ",")) require.Equal(t, []string{}, SplitNoEmpty(",,,", ","))