@@ -6,6 +6,35 @@ import (
66 "github.com/stretchr/testify/require"
77)
88
9+ func TestIsSpecifiedIPOrCIDR (t * testing.T ) {
10+ t .Parallel ()
11+ testCases := []struct {
12+ name string
13+ input string
14+ expected bool
15+ }{
16+ {"valid_ip" , "1.2.3.4" , true },
17+ {"valid_cidr" , "10.0.0.0/8" , true },
18+ {"valid_host_cidr" , "192.168.1.1/32" , true },
19+ {"all_traffic_cidr" , "0.0.0.0/0" , true },
20+ {"unspecified_ip" , "0.0.0.0" , false },
21+ {"unspecified_cidr_32" , "0.0.0.0/32" , false },
22+ {"unspecified_cidr_24" , "0.0.0.0/24" , false },
23+ {"unspecified_ipv6" , "::" , false },
24+ {"unspecified_ipv6_128" , "::/128" , false },
25+ {"invalid_string" , "not-an-ip" , false },
26+ {"empty_string" , "" , false },
27+ }
28+
29+ for _ , tc := range testCases {
30+ t .Run (tc .name , func (t * testing.T ) {
31+ t .Parallel ()
32+ result := IsSpecifiedIPOrCIDR (tc .input )
33+ require .Equal (t , tc .expected , result )
34+ })
35+ }
36+ }
37+
938func TestAddressStringToCIDR (t * testing.T ) {
1039 t .Parallel ()
1140 testCases := []struct {
0 commit comments