From 6f3415cb81dd20358a3dc1ec0805e10ba63fb8ba Mon Sep 17 00:00:00 2001 From: Euan Date: Fri, 1 Dec 2023 12:26:35 +0000 Subject: [PATCH 1/2] Added simple test --- pkg/core/core_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/core/core_test.go b/pkg/core/core_test.go index 6c454ee..8a7ff94 100644 --- a/pkg/core/core_test.go +++ b/pkg/core/core_test.go @@ -181,3 +181,8 @@ func TestContainsAddress(t *testing.T) { }) } } + +func TestParseCIDRError(t *testing.T) { + _, err := ParseCIDR("") + assert.Error(t, err, "Should return an error when given an empty string") +} From 6ef797b2db926cd58957a3ae9efc329e9122e031 Mon Sep 17 00:00:00 2001 From: Euan Date: Sat, 2 Dec 2023 19:10:54 +0000 Subject: [PATCH 2/2] expanded test criteria --- pkg/core/core_test.go | 44 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pkg/core/core_test.go b/pkg/core/core_test.go index 8a7ff94..04a7b70 100644 --- a/pkg/core/core_test.go +++ b/pkg/core/core_test.go @@ -182,7 +182,45 @@ func TestContainsAddress(t *testing.T) { } } -func TestParseCIDRError(t *testing.T) { - _, err := ParseCIDR("") - assert.Error(t, err, "Should return an error when given an empty string") +func TestParseCIDR(t *testing.T) { + tests := []struct { + name string + cidrStr string + wantErr bool + }{ + { + name: "Parse a valid IPv4 CIDR", + cidrStr: "10.0.0.0/16", + wantErr: false, + }, + { + name: "Parse a valid IPv6 CIDR", + cidrStr: "2001:db8:1234:1a00::/106", + wantErr: false, + }, + { + name: "Parse an invalid IPv4 CIDR", + cidrStr: "356.356.356.356/16", + wantErr: true, + }, + { + name: "Parse an invalid IPv6 CIDR", + cidrStr: "2001:db8:1234:1a00::/129", + wantErr: true, + }, + { + name: "Parse an empty CIDR", + cidrStr: "", + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := ParseCIDR(tt.cidrStr) + if (err != nil) != tt.wantErr { + t.Errorf("ParseCIDR() error = %v, wantErr %v", err, tt.wantErr) + return + } + }) + } }